我对.htaccess
和正则表达式还不太熟悉,但我很沮丧,可能是因为我过于复杂化了。基本上:
HTTP_HOST
will be one of several domains, and should be preserved as-is including subdomains, exceptwww.
should always be removed- only
domain1
and 'domain2' have SSL, soHTTPS
should be forced, but any others should be forced toHTTP
- if the first subfolder after the domain name is
foo
, then rewrite so thatfoo
is a subdomain instead of a subfolder. - after that, if
foo.
is the subdomain:- retain any missing/forbidden folders/file in the visible URL (to be handled later)
- the actual page for any of these is located at
foo.*.com/index.php
missing/forbidden pages not on the
foo
subdomain should still be sent to\index.php
in the root, which I'm currently doing with:RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ /index.php [last,nocase]
我的尝试:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ $1 [L]
RewriteCond %{HTTP_HOST} domain1\.ca [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L]
RewriteCond %{HTTP_HOST} !domain1\.ca [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L]
RewriteCond %{REQUEST_URI} ^/foo.* [NC]
RewriteRule ^ %{REQUEST_SCHEME}://foo\.%{HTTP_HOST}%{REQUEST_URI} [L]
RewriteRule "^/foo/(.+)" "%{REQUEST_SCHEME}://foo.%{HTTP_HOST}/$1" [L,NS,QSA,R=301]
一些例子:
incoming url: should become:
http://www.domain1.com/foo/blah => https://foo.domain1.com/blah
https://example.com/foo/blah.html => http://foo.example.com/blah.html
http://www.domain1.com/foo/index.php/foo => https://foo.domain1.com/foo
https://example.com/blah/blah.html => http://example.com/blah/blah.html
我希望这个内容有意义(我已经不知所措,时间也过去了!)- 谢谢!
https://bar.example.com/foo/blah.html
应该发生什么?或者这两种情况是互相排斥的吗? - 04FSbar.
并显示 URL 为https://foo.example.com/blah.html
(但仍然显示从index.html
中实际内容)。这有意义吗? - ashleedawg