我想要以下重定向
(1( 主域(任意TO HTTPS(
example.com
www.example.com
http://example.com
http://www.example.com
至
https://www.example.com
(2( 通配符子域(任意到HTTP(
据你们所知,使用通配符子域意味着任何东西都可以是子域,所以我想重定向的例子
reham.example.com TO http://reham.example.com
dave.example.com TO http://dave.example.com
egypt.example.com TO http://egypt.example.com
还有!记住要避免www.
像subdomain
一样计数
这是我的
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^((?!www.)[^.]+).example.com$
RewriteRule ^http://%1.example.com%{REQUEST_URI} [NE,L,R]
代码问题
它工作正常,但在我调用www.mysite.com
时失败,它将www.视为子域,然后将我重定向到HTTP
(www.example.com
(,同时它应该重定向到HTTPS
(https://www.example.com
(
两个RewriteCond可以被链接
第一个需要子域,第二个专门拒绝www。
# require a subdomain in URL
RewriteCond %{HTTP_HOST} ^([^.]+).example.com$
# Do not match if subdomain is www
RewriteCond %{HTTP_HOST} !^www.example.com$
# L removed, do not make this rule the last
RewriteRule ^http://%1.example.com%{REQUEST_URI} [NE,R]
# example.com or www.example.com
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^https://www.example.com%{REQUEST_URI} [NE,L,R]