将url重定向到root,然后重定向到子域

时间:2016-05-06 08:14:54

标签: apache .htaccess redirect url-rewriting

我想做以下重定向:

http://example.com to some static page
http://exmaple.com/<anything> to http://subdomain.example.com/<anything>

目前我有这个:

RewriteRule ^/?$ static/index.html [L]
RewriteRule ^(*)?$ http://sub.example.com/$1 [L]  

感谢任何帮助。 感谢

1 个答案:

答案 0 :(得分:1)

您可以尝试以下规则:

RewriteEngine on

#1)This will redirect the homepage of example.com to /static/index.html#
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^$ /static/index.html [NC,L]
#2)This will redirect  /anything  to sub.example.com#
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteCond %{REQUEST_URI} !^/static/index\.html [NC]
RewriteRule ^(.+)$ http://sub.example.com/$1 [NC,L,R,NE]
相关问题