[英]htaccess not redirecting to https
I have the following code in htaccess 我在htaccess中有以下代码
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]
I want it to redirect automatically the url to https But it is not redirecting. 我希望它自动将URL重定向到https,但它不重定向。 I tried changing 我尝试改变
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/films/$1 [R=301,L]
to 至
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/films/$1 [R=301,L]
To force HTTPs
you can use: 要强制使用HTTPs
,可以使用:
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
Therefore leaving you with https://
on everything. 因此,在所有内容上都使用https://
。 Including {REQUEST_URI}
is better than specifying the directory. 包括{REQUEST_URI}
比指定目录更好。 As it will then work for all directories also. 因为它将适用于所有目录。
As I recently learnt, it is better to combine your forced www
and https
, try using this: 据我最近了解,最好将您的强制www
和https
结合使用,尝试使用以下方法:
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]
To redirect to https, you can use the following redirect in /films/.htaccess
: 要重定向到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]
Clear your browser cache before testing this redirect. 在测试此重定向之前,请清除浏览器缓存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.