Forum Moderators: phranque

Message Too Old, No Replies

Need help on mod rewrite

Redirecting any dynamic links starting from host to clear host name

         

skaven

2:09 pm on Aug 18, 2006 (gmt 0)

10+ Year Member



Hi!

Please help me on my problem with mod_rewrite.

I need to redirect any dynamic starting URLs from host (/) to clear host name, i.e.:

http://www.example.com/?id -> http://www.example.com
http://www.example.com/?id=qwe -> http://www.example.com
etc.

I'm using next rules to catch query string:

RewriteCond %{QUERY_STRING} ^.+$
RewriteRule .+ http://www.example.com/? [R=301,L]

but that rules also catches an URLs like

http://www.example.com/search.html?param=... and so on

The question is - how to redirect ONLY from root (/), instead of keeping URLs like http://www.example.com/search.html?param=... working?

[edited by: jdMorgan at 2:43 pm (utc) on Aug. 18, 2006]
[edit reason]
[1][edit reason] Example.com [/edit]
[/edit][/1]

jdMorgan

2:42 pm on Aug 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just specify that the local URL-path must be blank (I assume this code is in .htaccess):

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

Jim