rewrite and permanent redirect with query strings

Discuss practical ways rearrange URLs using mod_rewrite.

rewrite and permanent redirect with query strings

Postby gateoflions » Fri Dec 07, 2007 11:56 pm

I want to rewrite this
forums.php?m=topics&s=15
to this
forum-topics-c15.html
and I have so far this
Code: Select all
RewriteRule ^forum-topics-c([^/]*)\.html$ /forums.php?m=topics&s=$1 [NC,NE,L]

but I want to add a 301 rule to make it permanently redirect to new format. I know how to make it work with 1 'variable', for example if the query was only forums.php?m=topics, the command should be something like
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?m=([^&]+)&.*)?$ [NC]
RewriteRule ^forums\.php$ /forum-%2.html? [R=301,L]

but what happens with more variables?
I tried this
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?m=([^&]+)&s=([^&]+)(&.*)?$ [NC]
RewriteRule ^forums\.php$ http://www.fmscout.com/forum-%2-c%3.html? [R=301,L]

with no luck.
thanks in advance for your time :)

EDIT:
I studied the forums for some hours and I think I made it work :D
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?m=topics(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?s=([^&]+)(&.*)?$ [NC]
RewriteRule ^forums\.php$ /forum-topics-c%2.html? [R=301,L]
gateoflions
 
Posts: 4
Joined: Thu May 31, 2007 1:12 pm

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 26 guests

cron