开发者

Mod_rewrite help

I'm trying to remove query strings from my calendar, but my mod_rewrite is not appending the query string.

The website is http://cacroche开发者_运维知识库ster.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


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.


To maintain query strings when rewriting, use the QSA (query string append) flag.

[NC,R=301,QSA,L]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜