0

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]
Jack
  • 25
  • 2
  • 5
  • possible duplicate of [Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?](http://serverfault.com/questions/214512/everything-you-ever-wanted-to-know-about-mod-rewrite-rules-but-were-afraid-to-ask) – GregD Jan 03 '11 at 00:59
  • It simply isn't working. Nothing in the URL changes. – Jack Jan 03 '11 at 00: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 03 '11 at 01: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 03 '11 at 01:03

2 Answers2

0

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&(.*)$

DerfK
  • 19,313
  • 2
  • 35
  • 51
0

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

Jack
  • 25
  • 2
  • 5