2011-02-16 112 views
1

嗨我想從一個URL重寫頁面發送數據,但不幸的是,它不工作,只是把我扔回主頁面或錯誤頁面。模板& urlrewrite爲rmbitter是我想要做的事。目前domain.com/rmbitter.php加載完美文件。我有域/ boothwall.html一個鏈接,該鏈接看起來像這樣domain.com/rmbitter.php?ulnk=$usr & slnk = $ LNK的rmbitter.tpl有$ _GET代碼。我相信我的問題是重寫它不允許變量被傳遞。url重寫和傳遞變量

之所以使用.tpl是因爲網頁有需要的設計佈局。如果我使用test.html頁面創建一個已啓動的rmbitter.php文件,並將其與rmbitter.php的鏈接與該變量一起工作正常。

$inc = array(
      'pictures' => 'icons.php', 
      'view_images' => 'templates/view_images.tpl', 
      'boothw' => 'templates/boothw.tpl', 
      'rmbitter' => 'templates/rmbitter.tpl' 
      ); 

//URL rewriting rules... 
$rew = array(
      '/view_images_public\/(.*)$/' => 'req=view_images&user=$1', 
      '/boothwall\.html$/' => 'req=boothw', 
      '/rmbitter\.php$/' => 'req=rmbitter' 
      ); 

url_rewrite.php

<?php 
//get request 
     $url = $_SERVER['REQUEST_URI']; 
     if (strpos($url,'?PHPSESSID=')) $url = substr($url,0,strpos($url,'?PHPSESSID=')); 
     while (strpos($url,'//') !== false) $url = str_replace('//','/',$url); 
     $url = substr($url,strlen(constant('dir'))); 
     $url_array = explode('/', $url); 

//make request string 
     $reqstr = ''; 
     foreach ($url_array as $key => $value) 
       $reqstr .= '/'.$value; 
     $reqstr = substr($reqstr,1); 

//other stuff 
    if (substr($reqstr,0,9) != 'index.php') { 

     $rewrite['/pages\/(.*)\.html$/'] = 'req=pages&id=$1'; 
     $rewrite['/static\/(.*)\.html$/'] = 'req=static&id=$1'; 
     $rewrite['/(.*)\.html$/'] = 'req=$1'; 
?> 

的.htaccess

<IfModule mod_rewrite.c> 
RewriteEngine On   
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*) index.php [L] 
</IfModule> 
+0

這些URL重寫規則實際應用在哪裏?你在用什麼? – 2011-02-16 18:08:34

回答

1

我不100%理解你的問題是什麼,但一般治癒所有獲取相關的mod_rewrite疾病是查詢字符串追加(QSA)。

RewriteRule ^(.*) index.php [L, QSA] 

顧名思義,它會將所有傳入的GET數據附加到新URL並將其傳遞給index.php。