2011-08-02 140 views
0

我試圖讓mod_rewrite的與以下網址工作:幫助mod_rewrite的

/events.php?view=details&id=$var 
/events.php?view=edit&id=$var 

顯然,我的目標是有/事件/信息/ $ VAR/事件/編輯/ $ VAR是我的真實URL,$ var是唯一的ID。

我的.htaccess文件

RewriteEngine On 

# redirect 301 /events.php http://www.google.com 
# If the rule above is active, it does redirect to google.com, 
# so .htaccess is working 

RewriteRule ^events/([^/]*)/([^/]*)\$ /events.php?view=$1&id=$2 [L] 

目前,當我去/events/details/$var它顯示/events.php但不拾取變量傳遞。

任何幫助,將不勝感激!

更新:我刪除了由OverZealous提到的.php。/events/details/$ var仍然顯示/事件。

// From events.php 
echo $_REQUEST['view']; //returns nothing 

UPDATE2: 我啓用了mod_rewrite的日誌(5級),並得到了以下的輸出:(我剝離出來的IP,日期,我的域名信息等)

[sid#7fc6d76f5608][rid#7fc6d79ad908/subreq] (3) [perdir /var/www/webroot/] add path info postfix: /var/www/webroot/events.php -> /var/www/webroot/events.php/details/35 
[sid#7fc6d76f5608][rid#7fc6d79ad908/subreq] (3) [perdir /var/www/webroot/] strip per-dir prefix: /var/www/webroot/events.php/details/35 -> events.php/details/35 
[sid#7fc6d76f5608][rid#7fc6d79ad908/subreq] (3) [perdir /var/www/webroot/] applying pattern '^events/([^/]*)/([^/]*)$' to uri 'events.php/details/35' 
[sid#7fc6d76f5608][rid#7fc6d79ad908/subreq] (1) [perdir /var/www/webroot/] pass through /var/www/webroot/events.php 

[sid#7fc6d76f5608][rid#7fc6d79a88e8/initial] (3) [perdir /var/www/webroot/] add path info postfix: /var/www/webroot/events.php -> /var/www/webroot/events.php/details/35 
[sid#7fc6d76f5608][rid#7fc6d79a88e8/initial] (3) [perdir /var/www/webroot/] strip per-dir prefix: /var/www/webroot/events.php/details/35 -> events.php/details/35 
[sid#7fc6d76f5608][rid#7fc6d79a88e8/initial] (3) [perdir /var/www/webroot/] applying pattern '^events/([^/]*)/([^/]*)$' to uri 'events.php/details/35' 
[sid#7fc6d76f5608][rid#7fc6d79a88e8/initial] (1) [perdir /var/www/webroot/] pass through /var/www/webroot/events.php 

[sid#7fc6d76f5608][rid#7fc6d7a597c8/subreq] (3) [perdir /var/www/webroot/] add path info postfix: /var/www/webroot/details -> /var/www/webroot/details/35 
[sid#7fc6d76f5608][rid#7fc6d7a597c8/subreq] (3) [perdir /var/www/webroot/] strip per-dir prefix: /var/www/webroot/details/35 -> details/35 
[sid#7fc6d76f5608][rid#7fc6d7a597c8/subreq] (3) [perdir /var/www/webroot/] applying pattern '^events/([^/]*)/([^/]*)$' to uri 'details/35' 
[sid#7fc6d76f5608][rid#7fc6d7a597c8/subreq] (1) [perdir /var/www/webroot/] pass through /var/www/webroot/details 
+0

問題解決 - [多視圖啓用] [1]默認情況下。 [1]:http://stackoverflow.com/questions/998491/why-is-my-variable-not-being-put-int-get – Matt

回答

2

爲什麼最後有\.php?你想要的網址是/events/details/123.php?因爲這不是你的榜樣。

我想你想你的重寫規則看起來像:

RewriteEngine On 
RewriteRule ^events/([^/]*)/([^/]*)$ /events.php?view=$1&id=$2 [L] 
+0

糟糕,那並不意味着在那裏。我一直在玩一個在線htaccess生成器,並且必須隱藏起來。即使使用更新後的代碼,它仍然不會返回傳入的變量。感謝您的迴應! – Matt

+1

那麼,下一步是啓用mod_rewrite日誌,這將允許您查看重寫是否正在進行:http://www.easymodrewrite.com/guide-logging – OverZealous

+0

好主意。我啓用它並添加了上面的日誌輸出。謝謝你的幫助! – Matt