关于wordpress的htaccess:为什么http到https似乎不起作用

时间:2017-08-15 12:22:20

标签: wordpress apache .htaccess

我想始终使用https访问wordpress admin。我使用它(从我读过的博客中复制并粘贴)

    # Redirection to HTTPS 
    RewriteCond %{SERVER_PORT} ^80$ [OR]
    RewriteCond %{HTTPS} =off
    RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

    # Redirection from www to non-www HTTPS
    RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
    RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

这不起作用。我总是要用铬手工修改网址。

1 个答案:

答案 0 :(得分:1)

尝试在第一行添加“RewriteEngine on”,我还会删除条件“%{HTTPS} = off”,条件“%{SERVER_PORT} 80”应该足够好。

RewriteEngine on
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]