Mod_Rewrite规则似乎不适用于服务器查询

时间:2011-11-01 11:45:17

标签: php apache mod-rewrite

我一直在努力使用似乎不起作用的mod_rewrite规则。简而言之,我想要以下网址: www.servername.com/showtest/1 重定向到: www.servername.com/showtest.php?id=1

我认为.htaccess中的以下内容应该让重定向工作:

RewriteEngine On
RewriteRule ^showevent/(\w+)/?$  showevent.php?id=$1 [L,R,QSA]

然而,它似乎不起作用,我认为PHP中的$ _GET和$ _REQUEST变量都是空的,据我所见。

我试过做一些调试,包括各种不同的正则表达式。我还打开了mod_rewrite日志以查看(我在本地服务器上工作)。这些是相关的:

127.0.0.1 - - [01/Nov/2011:12:25:55 +0100] [127.0.0.1/sid#b7843948][rid#b76d0058/subreq]   (1) [perdir /var/www/1277/] pass through /var/www/1277/showevent.php
127.0.0.1 - - [01/Nov/2011:12:25:55 +0100] [127.0.0.1/sid#b7843948][rid#b76db058/initial] (3) [perdir /var/www/1277/] add path info postfix:    /var/www/1277/showevent.php -> /var/www/1277/showevent.php/1
127.0.0.1 - - [01/Nov/2011:12:25:55 +0100] [127.0.0.1/sid#b7843948][rid#b76db058/initial] (3) [perdir /var/www/1277/] strip per-dir prefix: /var/www/1277/showevent.php/1 -> showevent.php/1
127.0.0.1 - - [01/Nov/2011:12:25:55 +0100] [127.0.0.1/sid#b7843948][rid#b76db058/initial] (3) [perdir /var/www/1277/] applying pattern '^showevent/(\w+)/?$' to uri 'showevent.php/1'
127.0.0.1 - - [01/Nov/2011:12:25:55 +0100] [127.0.0.1/sid#b7843948][rid#b76db058/initial] (3) [perdir /var/www/1277/] add path info postfix: /var/www/1277/showevent.php -> /var/www/1277/showevent.php/1

似乎不是重写为showevents.php?id = 1,而是重写为showevent.php / 1

我欢迎您提供任何帮助。

1 个答案:

答案 0 :(得分:1)

确实会发生这种情况,因为您在重写规则中使用了Flags。你想改变

  

[L,R,QSA]   只是“[L]”

请参阅http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriteflags以供参考。