Reputation: 607
I have two domains on the same server. One domain is for production and the other is for testing content before it is copied over to the production. I am trying to create a rewrite rule that redirects http to https. How can I write it so that domain name is not hard coded? The reason I need this is when I copy the tested content to the production server I don't want have to change the .htaccess file. Here is what I have but it doesn't work.
# Prevent SSL cert warnings
<IfModule mod_rewrite.c>
RewriteCond %{SERVER_PORT} !^443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
Upvotes: 0
Views: 138
Reputation: 9702
RewriteEngine On
# This checks to make sure the connection is not already HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
Upvotes: 0
Reputation: 785971
You're pretty close in your attempt.
You can try this rule:
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Upvotes: 1