Solved

Rewrite Rule to Ignore/Strip Certain Parameter

Posted on 2013-11-21
4
371 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 51

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 51

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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