2016-07-30 98 views
-1

所以在我的htaccess文件爲WordPress的網站,我有:通過htaccess的強制所有到https

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

我想要的進入去https://example.com所有URL

在(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版本?

回答

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> 
+0

仍然無法使用:http://domain.com/page/ = domain.com/page/ www.domain.com/page/ = domain.com/page/ – Mikey2004

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] 
0

您可以嘗試在你的.htaccess使用此:

RewriteEngine on 
RewriteBase/

RewriteCond %{HTTPS} !=on [OR] 
RewriteCond %{HTTP_HOST} ^www\. 
RewriteRule^https://%{SERVER_NAME}%{REQUEST_URI} [NE,L,R=301] 
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 
+0

使用www?我不這麼認爲。 – Croises

+0

似乎工作... – Mikey2004