我想重定向此
http://www.domain.com/test.php?sub=subdomain&type=cars
重定向到
http://subdomain.domain.com/cars
我已经有mod_rewrite规则做相反的事情:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.com [NC]
RewriteRule (.*) http://www.%2.com/index.php?route=$1&name=%1 [R=301,L]
用htaccess,帮帮我PLZ ......
答案 0 :(得分:0)
您可以在今天进行测试,在最后添加?,以便在重写后从返回的网址中取消$ {QUERY_STRING}:
RewriteCond %{QUERY_STRING} sub=([^&]+)&type=([^&]+)
RewriteRule ^test\.php$ http://%1.domain.com/%2? [R=301,L]
解析了来自RewriteCond的参数%1和%2的%{QUERY_STRING}。
测试:
http://www.domain.com/test.php?sub=subdomain&type=cars
重定向到:
http://subdomain.domain.com/cars
重写规则在vhosts文件或等效的apache2服务器配置中测试,也在.htaccess文件中测试,在后一种情况下,必须禁止根目录斜杠 / 。
答案 1 :(得分:0)
你可能想要这样的东西:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.com [NC]
RewriteRule (.*) /index.php?route=$1&name=%1 [L]
# then the redirect
RewriteCond %{THE_REQUEST} \ /index\.php\?route=([^&]+)&name=([^&\ ]+)
RewriteRule ^ http://%2.domain.com/%1 [L,R=301]