帮助mod_rewrite

时间:2011-08-02 05:40:59

标签: mod-rewrite url-rewriting

我试图让mod_rewrite使用以下网址:

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

显然我的目标是让 / events / details / $ var / events / edit / $ var 成为我的实际网址&$ 39;和$ 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 个答案:

答案 0 :(得分:2)

为什么最后有\.php?您希望网址为/events/details/123.php吗?因为那不是你的榜样。

我认为您希望重写规则如下:

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