homepage Welcome to WebmasterWorld Guest from 54.227.182.191
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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?
referer




msg:1517343
 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
[widgets.com...]

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?

 

referer




msg:1517344
 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]

[widgets.com...]
redirects to:
[widgets.com...]

but should be:
[widgets.com...]

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

referer




msg:1517345
 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!

jdMorgan




msg:1517346
 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.

Jim

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