Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

301 redirect from old dynamic url to new "seo" url

How do I match parameters?

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

10+ Year Member

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)

10+ Year Member

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)

10+ Year Member

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)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

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.