Solved

Rewrite Rule to Ignore/Strip Certain Parameter

Posted on 2013-11-21
4
367 Views
Last Modified: 2013-12-02
I am doing a number of URL rewrites and I have a some URL patterns where I would rather strip one of the params or ignore it when running the rule.

for example:
http://www.domain.com/page.php?name=Something Really & Bad&id=12
but then I might have another link for the same page that comes in as
http://www.domain.com/page.php?id=12

I would rather write one rule for both cases however right now I am stuck writing two rules for these redirects.

RewriteCond %{QUERY_STRING} ^(.*&)id=11$ [NC]
RewriteRule ^page\.php$ http://www.domain.com/pagename.html? [R=301,L]
RewriteCond %{QUERY_STRING} ^(.*&)id=18$ [NC]
RewriteRule ^page\.php$ http://www.domain.com/pagename2.html? [R=301,L]
RewriteCond %{QUERY_STRING} ^id=11$ [NC]
RewriteRule ^page\.php$ http://www.domain.com/pagename.html? [R=301,L]
RewriteCond %{QUERY_STRING} ^id=18$ [NC]
RewriteRule ^page\.php$ http://www.domain.com/pagename2.html? [R=301,L]

Open in new window


That takes care of both cases I would rather wrap that into one rule per page rather then two separate rules.

Any thoughts or magic?

Last thing is would you put this in .htaccess or httpd.conf, my only concern with htaccess is the # of rules that I will end up with being around 500 and it might be better in httpd.conf as I understand htaccess gets read on each page load where as httpd.conf is read into memory.
0
Comment
Question by:iceman19330
  • 2
4 Comments
 
LVL 50

Expert Comment

by:Steve Bink
ID: 39668020
Try this:
RewriteEngine On

RewriteCond %{QUERY_STRING} (.*&?)foo=bar&?(.*) [NC]
RewriteRule /?(.*) $1?%1%2 [NC]

Open in new window

0
 
LVL 14

Accepted Solution

by:
jb1dev earned 500 total points
ID: 39668022
Does this work for you?

    RewriteCond %{QUERY_STRING} ^(.*&)?id=11$ [NC]
    RewriteRule ^page\.php$ http://www.domain.com/pagename.html? [R=301,L]
    RewriteCond %{QUERY_STRING} ^(.*&)?id=18$ [NC]
    RewriteRule ^page\.php$ http://www.domain.com/pagename2.html? [R=301,L]

Open in new window

0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 39668027
Even better:
RewriteCond %{QUERY_STRING} (.*&?)id=(11|18)&?(.*) [NC]
RewriteRule /?(.*) $1?%1%3[NC]

Open in new window


You can continue to expand that list, or even replace with a RewriteMap call if you have a lot of them.
0
 

Author Closing Comment

by:iceman19330
ID: 39690080
This is the one I used and seems to do the trick.
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to generate a csr to request an intermediate ca on os x 3 50
Tool to email me when a website changes 29 133
Use System DSN 6 89
Public IP Address Amazon Servers 2 61
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question