Mod_rewrite帮助

时间:2010-10-21 23:10:03

标签: mod-rewrite query-string

我正在尝试从日历中删除查询字符串,但我的mod_rewrite没有附加查询字符串。

该网站为http://cacrochester.com/Calendar 如果单击该链接转到其他月份,查询字符串通常为http://cacrochester.com/Calendar?currentmonth=2010-11

根据我的规则,它只是不附加查询字符串,因此当您单击下个月的链接时,它只会保留在10月份。我的规则出了什么问题?

这是我的规则

RewriteCond %{QUERY_STRING} !^$
RewriteRule ^.*$ http://cacrochester.com/Calendar? [NC,R=301,L]

编辑:

我想要的是使用http://cacrochester.com/Calendar?currentmonth=2010-11之类的网址并将其转换为http://cacrochester.com/Calendar/2010-11

之类的内容

2 个答案:

答案 0 :(得分:2)

要在重写时维护查询字符串,请使用QSA(查询字符串追加)标记。

[NC,R=301,QSA,L]

答案 1 :(得分:2)

您可能需要您的应用输出相关网址,例如“/ Calendar / 2010-11”。这是一个简单的代码更改。

然后在Apache中你想要重写这些网址,使用:

RewriteRule ^/Calendar/([0-9]+-[0-9]{2})$ /Calendar.php?currentmonth=$1 [NC,QSA,L]

(您不希望RewriteCond用于此规则。)

强制R = 301的重定向只会公开内部网址方案。我认为这不是你想要的。