views:

36

answers:

2

Hey guys,

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

+2  A: 

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

[NC,R=301,QSA,L]

Dan Grossman
That didn't work.
Catfish
+2  A: 

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.

runningdogx
What do you mean `That's a simple code change`? Like a change to my PHP code?
Catfish
Yes, hence "your app". Webservers are not meant to do url rewriting of output from your php script. That would be a huge performance loss. If you want the end users to see urls like /Calendar/2010-11 then it's up to your php (or other dynamic language) application to output those urls. Usually this is done by setting one or several config variables (within your application) to control how those SEO-friendly urls are constructed.
runningdogx