Mod_rewrite 帮助
我正在尝试从日历中删除查询字符串,但我的 mod_rewrite 没有附加查询字符串。
该网站是 http://cacrochester.com/Calendar 如果您单击链接转到其他月份,则查询字符串通常为 http://cacrochester .com/Calendar?currentmonth=2010-11
根据我的以下规则,它只是不附加查询字符串,因此当您单击下个月链接时,它只会保留在十月。我的规则有什么问题吗?
这是我的规则
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^.*$ http://cacrochester.com/Calendar? [NC,R=301,L]
编辑:
我想要的是采用像 http://cacrochester.com/ 这样的网址Calendar?currentmonth=2010-11 并将其转换为类似 http://cacrochester.com/日历/2010-11
I'm trying to remove query strings from my calendar, but my mod_rewrite is not appending the query string.
The website is http://cacrochester.com/Calendar
and if you click the link to go to a different month, the query string is usually http://cacrochester.com/Calendar?currentmonth=2010-11
With my rule below, it just doesn't append the query string so when you click the next month link, it just stays on the month October. What's wrong with my rule?
Here is my rule
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^.*$ http://cacrochester.com/Calendar? [NC,R=301,L]
EDIT:
What i want is to take a url like http://cacrochester.com/Calendar?currentmonth=2010-11 and turn it into something like http://cacrochester.com/Calendar/2010-11
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要您的应用程序输出相对网址,例如“/Calendar/2010-11”。这是一个简单的代码更改。
然后在 Apache 中,您需要重写这些 url,使用:
RewriteRule ^/Calendar/([0-9]+-[0-9]{2})$ /Calendar.php?currentmonth=$1 [NC ,QSA,L]
(您不需要此规则的 RewriteCond。)
使用 R=301 强制重定向只会公开内部 url 方案。我不认为这就是你想要的。
You probably need your app to output relative urls like "/Calendar/2010-11". That's a simple code change.
Then in Apache you'd want to rewrite those urls, using:
RewriteRule ^/Calendar/([0-9]+-[0-9]{2})$ /Calendar.php?currentmonth=$1 [NC,QSA,L]
(You don't want a RewriteCond for this rule.)
Forcing a redirect with R=301 will only expose the internal url scheme. I don't think that's what you want.
要在重写时维护查询字符串,请使用 QSA(查询字符串追加)标志。
[NC,R=301,QSA,L]
To maintain query strings when rewriting, use the QSA (query string append) flag.
[NC,R=301,QSA,L]