2016-12-16 174 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

相关问题