Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect non-www and non-http to https

Yesterday I Installed SSL on the server. Since than I can't reach some pages.

www.example.com/amsterdam/shoes

example.com/amsterdam/

^ both do not redirect to https://, not even http://

www.example.com/amsterdam

^ does redirect to https://

How do I redirect all pages to HTTPS with www via .htaccess?

like image 798
Falch0n Avatar asked Jun 28 '16 07:06

Falch0n


2 Answers

RewriteEngine on


RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NC,L,R=301,NE]

This will redirect both http or non-www to https://www

like image 106
Amit Verma Avatar answered Oct 17 '22 17:10

Amit Verma


Use:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

OR you can try:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
like image 34
Sachin Singh Avatar answered Oct 17 '22 19:10

Sachin Singh