Ku Hye Sun Ku Hye Sun - 4 months ago 8
PHP Question

htaccess not redirecting to https

I have the following code in 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. I tried changing

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


to

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

Answer

To redirect to https, you can use the following redirect in /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.

Comments