htAccess 参数到子域



我想重定向这个

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,请帮助我...

你可能想要这样的东西:

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]

您可以通过在末尾添加 在最后禁止从返回的 URL 中抑制 ${QUERY_STRING} 来测试这一点,今天测试

RewriteCond %{QUERY_STRING} sub=([^&]+)&type=([^&]+)
RewriteRule ^test.php$ http://%1.domain.com/%2? [R=301,L]

%{QUERY_STRING} 解析来自 RewriteCond 的参数 %1 和 %2。

测试:

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

重定向至:

http://subdomain.domain.com/cars

重写规则在 vhosts 文件或 apache2 服务器配置的等效文件中进行测试,在 .htaccess 文件中进行测试,在后一种情况下,必须禁止根目录斜杠 /

最新更新