Mod rewrite help needed

kalekom

Junior Member
Joined
Jul 25, 2008
Messages
173
Reaction score
362
I have a small problem with redirecting.

I would like to redirect visitors from this aadress:

Code:
http://mysite.com/modules.php?name=Services

to

Code:
http://mysite.com/something/

I currently have tried:

Code:
RewriteEngine ON

RewriteRule   ^modules\.php?name=Services$ http://www.mysite.com/something/ [R=301,L]

but no luck...

Hope that someone can help.

Thanks.
 
You can't just plain redirect on the query string, you have to add a RewriteCond such as

Code:
RewriteEngine On
RewriteCond   %{QUERY_STRING} ^name=Services$
RewriteRule   ^modules\.php$ hxxp://w3.mysite.com/something/ [R=301,L]
 
Thanks, but this also passes query string to my new address. How to avoid that?
 
Try this:

RewriteEngine On
RewriteRule ^modules\.php\?name=Services$ http://mysite.com/something/ [L]
 
Let me know if this works for you:

Code:
RewriteEngine On
RewriteRule ^contact$ modules.php?name=Services [L]


_Austin
 
Thanks for trying Austin!

I have basic understanding how mod_rewrite works and this is not what I'm looking for.

Solution posted by purebackend works but it also sends query string (?name=Services) to new address that it will become http://mysite.com/something/?name=Services. I would just like to send visitors from

Code:
http://mysite.com/modules.php?name=Services

to

http://mysite.com/something/




Let me know if this works for you:

Code:
RewriteEngine On
RewriteRule ^contact$ modules.php?name=Services [L]


_Austin
 
Try this
Code:
RewriteEngine On
RewriteCond   %{QUERY_STRING} ^name=Services$
RewriteRule   modules\.php /something/ [R=301,L]
 
Try this
Code:
RewriteEngine On
RewriteCond   %{QUERY_STRING} ^name=Services$
RewriteRule   modules\.php /something/ [R=301,L]

Also passes query string name=Services so visitors will be redirected to www.mysite.com/something/?name=Services
 
what about this
Code:
RewriteEngine On
RewriteCond   %{QUERY_STRING} ^name=Services$
RewriteRule   modules\.php /something/? [R=301,L]
It will force query string to be null
 
what about this
Code:
RewriteEngine On
RewriteCond   %{QUERY_STRING} ^name=Services$
RewriteRule   modules\.php /something/? [R=301,L]
It will force query string to be null

Thanks, this works ok.
 
Back
Top