2016-12-16 173 views
0

目前,我的.htaccess文件中有以下關於論壇網站的信息。通過.htaccess將http重定向到https

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC] 
RewriteRule ^/?$ http://example.com/forums/ [L,R=301] 

它的工作原理非常適合像(HTTP)重定向一切://示例.com,www.example.com,(HTTP)://www.example.com中等來example.com/forums哪些是我想要的。

我現在想要將所有內容重定向到(https)://example.com/forums,但卻遇到了諸如example.com/forums/stuff等現有鏈接的問題。

我只能得到example.com重定向到https://example.com/forums,任何直接鏈接如example.com/forums/stuff等都不會重定向到https版本,有什麼想法?

+0

'重寫規則* HTTPS://%{HTTP_HOST}%{REQUEST_URI} [L,R = 301]'? – Cyclonecode

+0

[htaccess重定向到https:// www]的可能重複(http://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www) – Cyclonecode

回答

0

您需要2個重定向規則。一個規則的着陸頁重定向到論壇頁和另一個規則來重定向http -> https

RewriteEngine On 

# redirect landing page to /forums/ 
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com [NC] 
RewriteRule ^/?$ https://%{HTTP_HOST}/forums/ [L,R=301] 

# redirect http -> https 
RewriteCond %{HTTPS} off 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 
+0

第一個重定向規則有效,但由於某種原因,第二條規則無法將example.com/forums等現有鏈接轉發到https://example.com/forums – steveoverflow

+0

如果您有'/ forums/.htaccess',那麼將第二條規則放在該.htaccess中 – anubhava

+1

太棒了!這工作,謝謝你! – steveoverflow

相關問題