Solved

Rewrite Rule to Ignore/Strip Certain Parameter

Posted on 2013-11-21
4
359 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

948 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now