我試圖讓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
問題解決 - [多視圖啓用] [1]默認情況下。 [1]:http://stackoverflow.com/questions/998491/why-is-my-variable-not-being-put-int-get – Matt