2016-07-08 139 views
2

我在htaccess的htaccess的不是重定向到https

Options +FollowSymLinks -MultiViews 
RewriteEngine on 
RewriteBase /films/ 

RewriteCond %{REQUEST_METHOD} =POST 
RewriteRule^- [L] 

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/films/$1 [R=301,L] 

下面的代码我希望它自动重定向的URL为https 但它不重定向。我试图改变

RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/films/$1 [R=301,L] 

RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/films/$1 [R=301,L] 

回答

2

重定向到https,您可以使用/films/.htaccess下列重定向:

Options +FollowSymLinks -MultiViews 
RewriteEngine on 
RewriteBase /films/ 
RewriteCond %{HTTPS} !=on [OR] 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule ^(.*)$ https://www.example.com/films/$1 [R=301,L,NE] 

在测试此重定向之前清除浏览器缓存。

+0

谢谢,其工作@starkeen –

+0

使用https后,我的CSS不起作用。他们没有任何方式,CSS和JS文件也自动重定向到https @starkeen –

+0

这会将所有内容都重定向到/ films文件夹中的https。这些文件位于哪里? – starkeen

3

迫使你可以使用HTTPs

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

所以离开你https://上的一切。包括{REQUEST_URI}比指定目录要好。因为它也适用于所有目录。

正如笔者近日了解到,这是更好地结合你被迫wwwhttps,请尝试使用此:

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

我必须使用此代码,因为它是或改变任何东西? @thickguru –

+0

请按原样使用它。 – Lag

+0

放置代码的位置。我是否需要从我的htaccess中删除任何代码。 @thickguru –