Irfan Mir
Irfan Mir

Reputation: 2175

.htaccess rule for redirecting everything to https:// that thing

What is the proper .htacess rule to redirect every request by a user to any page on my server to https://that page

For example, mydomain.com or http://mydomain.com would go to https://mydomain.com

Also, mydomain.com/projects/1.html would go to https://my domain.com/projects/1.html

No matter how deep the requests go, all requests from the browser go to be https://that location.

How would I do this?

Upvotes: 0

Views: 54

Answers (2)

user1341970
user1341970

Reputation: 469

If you are using Apache, you need to use mod_ssl by using the SSLRequireSSL Directive. then you need to use mod_rewrite for a redirection.

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

Upvotes: 1

Niels Keurentjes
Niels Keurentjes

Reputation: 41958

RewriteEngine on
RewriteRule (.*) https://mydomain.tld$1

Ensure the vhosts are in different folders so it doesn't go recursive obviously.

Upvotes: 1

Related Questions