David J
David J

Reputation: 13

Redirect all requests with http to https

I need to redirect all requests with http to https. It is difficult to me to do with php headers. Is there any perfect way to do it?

Upvotes: 1

Views: 46

Answers (2)

Professor Abronsius
Professor Abronsius

Reputation: 33813

A slightly different approach - again done in .htaccess

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]

Upvotes: 0

Nuwan Chinthana
Nuwan Chinthana

Reputation: 135

You can use .htaccess to redirect users to a different URL. Include a .htaccess file with the following rules in www folder to direct incoming traffic from HTTP to HTTPS

RewriteEngine On
RewriteCond %{HTTPS} !on$
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Upvotes: 1

Related Questions