Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

How would I go about rewriting:

http://www.example.com/foo.html?order=desc&limit=all&something=else

to

http://www.example.com/foo.html?order=desc&something=else

I want to remove all instances on limit=all regardless of how many other parameters in the url.

I have tried:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{QUERY_STRING} ^(.*&)&limit=all(&.*)?$ [NC]
RewriteRule ^foo\.html$ /foo\.html\?%1%2 [R=301,L]
share|improve this question
    
    
It simply isn't working. Nothing in the URL changes. –  Jack Jan 3 '11 at 0:59
    
What is the actual problem/error you are having? You've stated that you tried something, and it didn't do what you expected; but you haven't specified why it was wrong. Offhand you might want to rethink those ampersands unless you're sure there will always be parameters before and after the "limit" parameter. Also you didn't mention "RewriteEngine On" –  Chris S Jan 3 '11 at 1:01
    
As I stated, the rewrite is not doing anything. No errors. Everything just stays the same. I am sure that there will always be parameters either side of the limit parameter. –  Jack Jan 3 '11 at 1:03

2 Answers 2

You have ^(.*&)&limit=all(&.*)?$ which expects two ampersands in a row before limit.

Since you're certain that you'll always have parameters on both sides of the limit=all, change it to ^(.*&)limit=all&(.*)$

share|improve this answer
up vote 0 down vote accepted

After a bit more playing around I was able to achieve this with the following:

RewriteCond %{QUERY_STRING} ^(.*)limit=all\&(.*)$ 
RewriteRule ^foo\.html$ http://www.example.com/foo\.html?$1%1%2 [R=301,L]

Thanks to Chris S for the suggestion to remove the ampersands

share|improve this answer
    
Please mark this answer as accepted. –  Andrew M. Jan 3 '11 at 5:54
    
I cannot mark this answer as accepted for 2 days –  Jack Jan 3 '11 at 6:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.