Reputation: 73
I have lost few hours on .htaccess rewrite I have this url:
http://xxx.yyy.zzz.net/html/login.php?sub=string
And I want change it to this
http://string.yyy.zzz.net/html/login.php
Upvotes: 0
Views: 66
Reputation: 2488
This approach is limited to one parameter name:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?xxx\.yyy\.zzz\.net
RewriteCond %{QUERY_STRING} ^sub=(.*)$
RewriteRule ^html/(.*)$ http://%1.xxx.yyy.zzz.net/$1? [L] <--note the use of %1
The problem is (as outlined here: http://wiki.apache.org/httpd/RewriteQueryString): mod_rewrite can not directly access and manipulate query parameters, your possiblities are quite limited. If you only have one kind of parameters that manages your redirect, you're good to go.
(NOTE: if you have other query parameters that you want to hand over to the target, leave out the final question mark. This effectively removes the rest of the query string. Also, the second rewrite condition had to be rewritten to end at the parameter)
Upvotes: 1