2014-11-03 173 views
0

我希望你能幫我用下面的htaccess重寫規則。htaccess wordpress https重寫規則

# BEGIN WordPress 

# WPhtc: Begin Custom htaccess 
# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{SERVER_PORT} !^443$ 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] 

RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 

我最近改變了從http我的WordPress網站到https ......問題是,舊的URL重定向到一個域名,而不是該頁面的HTTPS版本

如果我訪問以下頁面https://domain.com/test/testing/它工作100%,現在如果我將https部分更改爲http然後頁面重定向到https://domain.com而不是https://domain.com/test/testing/我該如何解決它,以便如果您轉到舊版本頁面http://domain.com/test/testing/(非https版本),它redir而不僅僅是域名https://domain.com

+0

http://stackoverflow.com/questions/4083221/how-to-redirect-all-http-requests- to-https – 2014-11-03 17:05:52

+0

您是否已將網站和主頁URL更改爲永久鏈接中的「https://」? – anubhava 2014-11-03 17:20:13

+0

嗨Anubhava,是的,我已經完成了它...它適用於https://完美,但只要你訪問一箇舊的鏈接,然後它重定向到家庭https://版本,而不是https格式的頁面... – 2014-11-03 17:25:01

回答

2

您必須找到%{REQUEST_FILENAME}的解決方法,因爲這隻能表示被訪問的文件。但你顯然想訪問SSL vHost。 所以你可能會將https硬編碼到你的.htaccess中。

RewriteEngine On 
RewriteCond %{HTTPS} !on 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

This可能會幫助你很多。 (發現上面的代碼)

0

我一直在努力解決這個問題,最後我發現了一個解決方案,在主頁重定向和wordpress在同一個htaccess文件中,最後它也適用於舊的http鏈接,重定向到https:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,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 
0

我試過你的解決方案。它運行良好,但如果你這樣做,你需要手動改變你所有的內部鏈接。 這工作得更好;)

RewriteEngine On 

RewriteCond %{SERVER_PORT} 80 

RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L] 
0

我用這個的.htaccess爲WordPress

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{ENV:HTTPS} !=on 
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L] 

# BEGIN WordPress 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule>