2

我知道这是一个常见的话题,但我已尽我所能在我在网上找到的解决方案的帮助下解决它。

我们有一个链接到子域 secure.mysite.com 的证书,我们希望实现以下目标:

  1. 我们需要在以下路径及其子页面上强制 SSL:http:
    //mysite.com/services[/.../...] => https://secure.mysite.com/services[/... /...]
    http://mysite.com/login[/.../...] => https://secure.mysite.com/login[/.../...]
    http:// /mysite.com/member[/.../...] => https://secure.mysite.com/member[/.../...]
    http://mysite.com/admin[/ .../...] => https://secure.mysite.com/admin

  2. 我们想在所有非安全路径上添加 www(除上述路径外的所有路径)

  3. 我们要删除所有安全路径上的 www(上面提到的所有路径)

以下是我放入 .htaccess 文件中的内容,但没有成功:

# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(services|login|member|admin)$ https://secure.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(services|login|member|admin)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# remove www from host when HTTPS
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteCond %{HTTPS} =on
RewriteRule ^ http%2://%1%{REQUEST_URI} [L,R=301]

# add www from host when HTTP
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# Zend redirect logic
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
4

1 回答 1

2

进行一些更正:

RewriteEngine On

# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(services|login|member|admin) https://secure.mysite.com%{REQUEST_URI} [L,R=301]

# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(services|login|member|admin) http://mysite.com%{REQUEST_URI} [L,R=301]

# remove www from host when HTTPS
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

# add www from host when HTTP
RewriteCond %{HTTPS} =off
RewriteCond %{HTTP_HOST} !^(www|secure)\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
于 2013-10-10T10:23:40.323 回答