逆转 mod_rewrite 规则

逆转 mod_rewrite 规则

我想要重定向来自以下地址的访问:

http://www.example.com/test.php?sub=subdomain&type=cars

http://subdomain.example.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]

我需要对这些规则做哪些更改才能将请求从脚本重定向到子域?

答案1

RewriteEngine On

RewriteCond %{QUERY_STRING} ^sub=(.+)&type=(.*)$
RewriteRule . http://%1.example.com/%2?

相关内容