2014-09-30 29 views
-1

我試圖做一個URL重寫使用.htaccess這是工作,但問題是,當我點擊鏈接時,它顯示地址欄上的URL重寫很好,但頁面顯示此錯誤內部服務器錯誤,我打開必要的東西,我需要打開我的瓦特像(LoadModule rewrite_module modules/mod_rewrite.so),所以我怎麼能解決這個下面是我的代碼下面這些頁面index.php,venues.php(其中包含類),landing.php(顯示地址欄上的rewiting,但顯示內部服務器錯誤)和.htaccess。正在工作的網址重寫與內部服務器錯誤

index.php 
include_once("venues.php"); 

$venue = new venues; 

$thedate = $venue->listAllVenue();    

if (count($thedate)) { 
    for ($i =0; $i < count($thedate); $i++) { 
     $id = $list[$i]['id']; 
     <a href="<?php echo venues::theurl($list[$i]['id'], "venue"); ?>"><?php echo $list[$i]['venue_title']; ?></a> 
    } 

venues.php 
class venues{ 
    function OneVenue($id, $point='id') { 
     $query = "SELECT * FROM venues WHERE id = '".$id."'"; 
     $sql = mysql_query($query) or die (mysql_error()); 

     if ($sql) { 
      $result = array(); 
      $row = mysql_fetch_array($sql); 
      $result['id'] = $row['id']; 
      $result['venue_title'] = $row['venue_title']; 
      return $result; 
     } else { 
      return false; 
     } 
    } 

    function theurl($id, $point="", $type="") { 
     if ($point == "venue") { 
      $data = venues::OneVenue($id); 
      $id = $data['id']; 
      $thename = trim(strtolower($data['venue_title'])); 

      $urlLink = explode(" ", $thename); 
      $sublink = implode("-", $urlLink); 

      $result = URL."venue-details/".$id."/".$sublink."/"; 
     } 
    return $result; 
    } 
} 

landing.php 
include_once("venues.php"); 
$venue = new venues; 

if (isset($_REQUEST['id'])) { 
    $id = $_REQUEST['id']; 
    $pickvenue = $venue->OneVenue($id); 
    echo $pickvenue['venue_title']; 
} 

.htaccess 
RewriteEngine on 
RewriteRule ^venues/([a-zA-Z)([0-9]+)/(.*?)/$ venue-details?id=$1 


RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php 
+0

in venues.php您在'$ result = URL'行中使用了一個全局變量'URL'「venue-details /".$ id。」/「。$ sublink。」/「; '你有沒有明確地設置這個全局變量?它應該看起來像'define('URL','www.mysite.com');'或類似的東西。 – Novocaine 2014-09-30 10:28:51

+0

也在同一個文件中,你正在做一個sql查詢(這種方式容易受到sql注入的影響),但我沒有看到任何連接到數據庫函數。 – Novocaine 2014-09-30 10:30:46

回答

0

你的索引頁被打破

代碼

include_once("venues.php"); 
$venue = new venues; 

$thedate = $venue->listAllVenue();    
if (count($thedate)) { 
for ($i =0; $i < count($thedate); $i++) { 
$id = $list[$i]['id']; 
<a href="<?php echo venues::theurl($list[$i]['id'], "venue"); ?>"><?php echo $list[$i]['venue_title']; ?></a> 
} 

爲什麼它是無效的

if (count($thedate)) { // <- has no closing bracket 
    for ($i =0; $i < count($thedate); $i++) { 
     $id = $list[$i]['id']; 
     // the line below just starts hmtl output with no closing php tags 
     <a href="<?php echo venues::theurl($list[$i]['id'], "venue"); ?>"><?php echo $list[$i]['venue_title']; ?></a> 
    } 

將其更改爲以下並再次嘗試;

include_once("venues.php"); 
$venue = new venues; 

$thedate = $venue->listAllVenue(); 
if (count($thedate)) 
{ 
    for ($i =0; $i < count($thedate); $i++) 
    { 
     $id = $list[$i]['id']; 
     ?> 
     <a href="<?php echo venues::theurl($list[$i]['id'], 'venue'); ?>"><?php echo $list[$i]['venue_title']; ?></a> 
     <?php 
    } 
} 
+0

仍然給我相同的錯誤(內部服務器錯誤) – 2014-09-30 10:22:58