QUERY_STRING and QSA

Discuss practical ways rearrange URLs using mod_rewrite.

QUERY_STRING and QSA

Postby ph2 » Thu Nov 20, 2008 3:02 pm

Is it possible to use both QUERY_STRING and QSA in the same rewrite rule? I'm trying to implement a rule that fires if a particular parameter is present, and then append a new parameter to the existing query string. What I have tried is something like this:

Code: Select all
RewriteCond %{QUERY_STRING} category=([^&]+)
RewriteRule ^(index\.html)$ /?blah=abc&oldcategory=%1 [QSA,L]


I get a 500 Internal error using this syntax. How can I best accomplish this? Thanks.
ph2
 
Posts: 1
Joined: Thu Nov 20, 2008 2:57 pm

Postby richardk » Fri Nov 21, 2008 12:56 pm

Does it work if you don't use index.html? index.html is special because it is (usually) loaded for / as well. It may be looping because the request to /?blah=abc&oldcategory=abc&category=abc also contains category=abc so may match the rule again.

Do you want it to work for / and /index.html?
Should category= be in the new query string?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)category=([^&]+)(&.*)?$ [NC]
RewriteRule ^(index\.html)?$ /?%1blah=abc&oldcategory=%2%3 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 30 guests

cron