2016-08-05 85 views
1

我已經設置了我的.htacess文件中的以下內容: 一個非WWW重定向到www 和http到https301重定向,.htaccess文件HTTP-HTTPS

這似乎如果我訪問非WWW做工精細文件將轉發到

問題是,如果我使用非https訪問單個頁面,它仍然會呈現並且不會轉發到https版本。

我該如何解決這個問題? RewriteOptions繼承上

# 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 

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^mywebsite.co.uk [NC] 
RewriteRule ^(.*)$ https://www.myswebsiye.co.uk/$1 [L,R=301] 

RewriteCond %{HTTP_HOST} ^mywebsite\.co\.uk$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.co\.uk$ 
RewriteRule ^index\.html$ "https\:\/\/www\.mywebsite\.co\.uk\/" [R=301,L] 

回答

0

RewriteEngine敘述你可以用它來取代這兩個力WWW和力HTTPs

RewriteEngine On 

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

上面的代碼集成了兩個,迫使WWW並迫使HTTPs

+0

所以,如果我輸入我的網頁的URL,並使用非HTTPS與上面的代碼應該重定向? – Timmer

+0

我已經添加了.htaccess文件我現在有 – Timmer

+0

'#End Wordpress'下的任何東西,替換上面我所說的。上面應該將這樣一個URL:'http:// example.com'轉換爲'https:// www.example.com' – Lag

0

我有一個像你一些問題,你可以編輯.htaccess到:

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