homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

301 redirect from old dynamic url to new "seo" url
How do I match parameters?

 6:56 am on May 5, 2006 (gmt 0)

My current setup in .htaccess:

RewriteEngine on
RewriteRule ^oldstuff.php$ http://www.widgets.com/ [R=301,L]

This almost works as expected. Except:

When user goes to old page [widgets.com...]

he gets redirected to

I don't want that to happen. How can I prevent it?

Also, this doesn't seem to work either:

RewriteEngine on
RewriteRule ^oldstuff.php?q=(.*)$ http://www.widgets.com/query/$1 [R=301,L]

Isn't it possible for the RewriteRule to match on parameters?



 8:06 am on May 5, 2006 (gmt 0)

First problem solved:

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^oldstuff.php$ http://www.widgets.com/ [R=301,L]

Second problem NOT solved (but I think I'm close):

RewriteCond %{QUERY_STRING} ^q=(.*)$
RewriteRule ^oldstuff.php$ http://www.widgets.com/query/%1 [R=301,L]

redirects to:

but should be:

What am I doing wrong? Why does the query string get appended to the result?


 8:31 am on May 5, 2006 (gmt 0)

Last problem solved!

RewriteCond %{QUERY_STRING} ^q=(.*)$
RewriteRule ^oldstuff.php$ http://www.widgets.com/query/%1? [R=301,L]

The solution was putting a questionmark at the end of the RewriteRule. I don't understand why. But it works!

If anyone could give me an explanation, I would appreciate it!


 2:00 pm on May 5, 2006 (gmt 0)

This query-string-clearing function is described in the Apache mod_rewrite documentation [httpd.apache.org].

When you want to erase an existing query string, end the substitution string with just the question mark.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved