强制所有通过htaccess https

时间:2016-07-30 11:36:52

标签: wordpress .htaccess https

因此,在我的WordPress网站的htaccess文件中,我有:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

我想要输入的所有网址都转到https://example.com(https,没有www。)

目前此处运作良好:

http://example.com = https://example.com 
www.example.com = https://example.com

然而,在页面上它不起作用:

http://example.com/page/ = example.com/page/
www.example.com/page/ = example.com/page/

如何将其转到https版本?

4 个答案:

答案 0 :(得分:0)

将htaccess文件更改为以下内容,它将对您有用。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^$ https://example.com/? [L,R=301]
</IfModule>

答案 1 :(得分:0)

您可以使用:

RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

答案 2 :(得分:0)

您可以在.htaccess

中尝试使用此功能
RewriteEngine on
RewriteBase /

RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [NE,L,R=301]

答案 3 :(得分:0)

这似乎已经成功了......

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
# END WordPress