2017-08-15 81 views
-1

我想要隨時訪問WordPress的管理與HTTPS。我使用這個(從我讀的博客複製和粘貼)htaccess在WordPress的:爲什麼HTTP到HTTPS似乎並不工作

# 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

嘗試在第一行添加「RewriteEngine on」,如果條件「%{SERVER_PORT} 80」應該足夠好,我還會刪除條件「%{HTTPS} = off」。

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]