我的.htaccess文件中已经有以下内容:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]但是我想添加一个这样的规则:
RewriteCond %{HTTP_HOST} ^(.+).example.com
RewriteRule ^(.*)% http://example.com/?name=%1&type=$1 [R,L]但如果没有绑定到example.com,它必须在任何域上工作。
发布于 2012-03-04 10:10:48
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.com [NC]
RewriteRule (.*) http://www.%2.com/?name=%1 [R=301,L]将http://subdomain.domain.com重写为http://www.domain.com/?name=subdomain
要将两者结合起来,可以尝试如下所示
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]这会将http://subdomain.domain.com/hello-world重定向到http://www.domain.com/index.php?route=hello-world&name=subdomain
https://stackoverflow.com/questions/9551603
复制相似问题