SSL www有效,但并非没有

时间:2014-02-01 19:45:16

标签: .htaccess ssl

如果我访问我的网站www.xyz.com,浏览器会返回https://xyz.com。如果我在xyz.com上访问我的网站,浏览器会返回xyz.com。在xyz.com中输入时,如何强制浏览器显示https://xyz.com?我正在使用以下.htaccess代码。

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*\.)*xyz.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*\.)*www.xyz.com$ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://xyz.com/$1 [R]

2 个答案:

答案 0 :(得分:0)

尝试使用[OR]重写条件标志(您也可以组合前两个):

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} www\.xyz\.com$ [NC]
RewriteRule ^(.*)$ https://xyz.com/$1 [R,L]

答案 1 :(得分:0)

感谢Jon Lin,当我将代码用于此代码时,空白页现在正在工作。

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
相关问题