Redirect rule not working with parameter based url

New to mod_rewrite? This is a good place to start.

Redirect rule not working with parameter based url

Postby taurianthebull » Thu Sep 03, 2009 6:20 pm

I am trying to use this simple rule:

Code: Select all
Redirect /ht/oldpage.html?hey=hi http://localhost/ht/new-link.php [R=301,L]

but its not working :(

But if i eliminate url parameters, then it works. For example, this code works:
Code: Select all
Redirect /ht/oldpage.html http://localhost/ht/new-link.php [R=301,L]

Any ideas?
How to make it work?



Thanks![/code]
taurianthebull
 
Posts: 6
Joined: Thu Sep 03, 2009 2:15 pm

Postby taurianthebull » Thu Sep 03, 2009 6:26 pm

One more thing, i have a set of predefined urls with parameters, all i want to do is simply check for them if they are requested, and then transfer them to another url.

No parameter exchange required.

Code: Select all
Like:
http://www.domain.com/prod.php?id=2  --->  http://www.domain.com/production-product-title/



Any ideas?
taurianthebull
 
Posts: 6
Joined: Thu Sep 03, 2009 2:15 pm

Postby richardk » Sat Sep 05, 2009 8:08 am

Redirect is part of mod_alias not mod_rewrite. It does not use mod_rewrite flags ([R=301,L]). A correct 301 redirect with Redirect would be
Code: Select all
Redirect 301 /oldpage http://www.example.com/newpage


Mod_alias is for simple redirects, you need mod_rewrite for redirecting query strings
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?hey=hi(&.*)?$ [NC]
RewriteRule ^ht/oldpage.html$ /ht/new-link.php? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby taurianthebull » Sat Sep 05, 2009 8:12 am

Thanks!!
taurianthebull
 
Posts: 6
Joined: Thu Sep 03, 2009 2:15 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 38 guests

cron