我需要将每个* .example.com重定向到除www.example.com和example.com之外的其他域,我需要提供index.php文件......
我试试:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} !^(www|)\.example\.com$ [NC]
RewriteRule ^(.*)$ http://app.example.com/%1/$1 [P,NC,QSA]
</IfModule>
但无法工作 - 任何子域重定向到index.php 如何解决我的问题?
更新
我用这段代码解决了这个问题:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ^(\w+)\.exampe\.com$
RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)/([^:]*):\1
RewriteRule ^(.*)$ http://app.example.com/m/%1/$1 [L,NC,QSA]
</IfModule>
但现在浏览器清除了我的子域名等london.example.com
并向我显示app.example.com/m/london
...如何将我的子域保留在浏览器栏中?
答案 0 :(得分:0)
应使用[P]
flag:
RewriteCond %{HTTP_HOST} !^((www|app)\.)?example\.com
# check if the host is not app.example.com www.example.com example.com
RewriteCond %{HTTP_HOST} ^(\w+)\.example\.com [NC]
# check if the host is subdomain of example.com
RewriteRule ^(.*) http://app.example.com/m/%1/$1 [QSA,P]
# proxy the request to http://app.example.com/%1/$1
# %1 is the back reference to the grouped part (\w+)
# $1 is the back reference to the grouped part (.*)