Catfish
Catfish

Reputation: 19284

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://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

Upvotes: 0

Views: 64

Answers (2)

runningdogx
runningdogx

Reputation: 533

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.

Upvotes: 2

Dan Grossman
Dan Grossman

Reputation: 52372

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

[NC,R=301,QSA,L]

Upvotes: 2

Related Questions