views:

15

answers:

1

Hey guys, I am hosting my own server and have two ip addresses for it (one for people connecting from within intranet and one for people connecting from outside) and I have two dynamic dns's redirecting to these ip's. I have just installed/setup SSL on my apache2-based server, and am trying to use .htaccess to force users to use https. I got it working using a statement like

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

The problem is that since I have two separate domain names for the same website, that statement will redirect all traffic to one specific domain. I guess what I'm asking is whether there is a.) a way to put a conditional if statement to check for their ip, or preferably b.) a way to remove the "mywebsite" from being hardcoded, and putting a variable for whatever the user enters.

Any help would be greatly appreciated.

+1  A: 

Well I searched for about half an hour, and then right after I posted on SO I found the answer...lol. For anyone who is trying to do a similar thing all you have to do is use a variable for the web address, instead of hard coding it.

The way I did it was by adding this to my .htaccess:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

This way it simply will take any url entered and change it from http to https

Cheers

Joe
You can click on the empty tick to mark a question as answered. And as a bonus (at least if it is someone else answers), both of you will get reputation points.
nhnb