0

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> 

2 Answers 2

1

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] 
Sign up to request clarification or add additional context in comments.

6 Comments

For clarification, are you filling in the SERVER_NAME or leaving it as written?
Didn't understand your question. As you can see I am not using SERVER_NAME in my answer just using HTTP_HOST
Sorry, are you filling in the HTTP_HOST then or leaving it as written?
Question is about http -> https so HTTP_HOST is carried over to https URL
Ok, so you don't need to replace HTTP_HOST with www.example.com?
|
0
RewriteEngine On # This checks to make sure the connection is not already HTTPS RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.