0

I am trying to make sure that if HTTPS is used outside of the secure subdomain it gets redirected to HTTP.

This is what I have in the root .htaccess file:

# Redirect HTTPS requests for non-SSL pages back to HTTP. (Note that shared objects
# such as images are excluded from this rule)

RewriteCond %{HTTPS} =on

# my.EXAMPLE.com is the secure subdirectory.
RewriteCond %{HTTP_HOST} !^my.EXAMPLE.com [NC]

RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$
RewriteRule ^(.*)$ http://www.EXAMPLE.com/$1 [R=301]

Put simply:

if HTTPS
if not in my.example.com
if NOT an image/css/js file
redirect to HTTP

But this is not working as expected, instead if I try to access a page outside of the my.example.com sub-directory via HTTPS I get a 404 Not Found error. Accessing the same page via HTTP has no problems, it works fine.

Any idea why this rule may not be working?

EDIT

Here's the entire .htaccess file:

# Don't display .htacess files in directory listings.
IndexIgnore .htaccess
Options +FollowSymLinks
RewriteEngine on

# Password protected for now
AuthType Basic
AuthName "EXAMPLE"
AuthUserFile "/home/EXAMPLE/.htpasswds/public_html/passwd"
require valid-user

# Redirect HTTPS requests for non-SSL pages back to HTTP. (Note that shared objects
# such as images on both HTTP and HTTPS pages are excluded from this rule)
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^my\.EXAMPLE\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png|ico|css|js)$
RewriteRule ^(.*)$ http://www.EXAMPLE.com/$1 [R=301]


# Redirect non-www requests to www
RewriteCond %{HTTP_HOST} ^EXAMPLE.com$
RewriteCond %{HTTP_HOST} !^my\.EXAMPLE\.com [NC]
RewriteRule ^(.*)$ "http\:\/\/www\.EXAMPLE\.com\/$1" [R=301]

# Prevent direct access to the WHMCS folder must be accessed through secure subdomain
RedirectMatch 301 ^/WHMCS/(.*)$ https://my.EXAMPLE.com/$1

    
ErrorDocument 404 /404.php
4

2 回答 2

0

尝试这个 :

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^my\.EXAMPLE\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png|ico|css|js)$
RewriteRule ^(.*)$ http://www.EXAMPLE.com/$1 [R=301]
于 2012-08-31T08:28:02.583 回答
0

问题是,如果您没有为 设置 SSL 虚拟主机www.example.com,并将其文档根目录指向非 SSL 虚拟主机所在的www.example.com位置,那么当有人访问 时https://www.example.com/,您的 htaccess 文件将永远不会被读取。我敢打赌,您需要将 HTTPS->HTTP 规则放在 SSL vhost 的 htaccess 文件中(my.example.com文档根目录在哪里)。

你所拥有的似乎是:

http://www.example.com/ -> /home/EXAMPLE/ (or whatever your document root is)

https://my.example.com/ -> /home/EXAMPLE/subfolder/

因此,如果没有 vhost 设置,当您访问 SSL example.com 时,永远不会访问https://www.example.com其中的 htaccess 文件。/home/EXAMPLE/

于 2012-08-31T08:56:41.607 回答