我的.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
,它必须适用于任何域。
答案 0 :(得分:3)
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