Reputation: 476
I am struggling with mod_rewrite htaccess for at least couple of days, and still cannot figure this out.
I want to force HTTPS SSL on my site, but only from outside of the network.
I have something like this:
RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.30
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R,L]
My local IP is 192.168.1.30
and it keeps correcting my adress to https://www.mysite.com
.
In one condition it allows me to connect locally to my server. When I type https://192.168.1.10
(my local server adress). But it keeps throwing me SSL caution which cannot be kept this way.
When I type http://192.168.1.10
it redirects me to https://www.mysite.com
How to make it leave my ip alone from all the redirects?
For my logic, it should not redirect me no matter what if my REMOTE_ADDR
is 192.168.1.30
.
Upvotes: 1
Views: 139
Reputation: 785128
Can you try this rule:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^(192\.168\.|127\.0\.0\.1)
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Upvotes: 1
Reputation: 594
I do not think you need Rewrite rules at all. Since HTTP listens on port 80 and HTTPS on port 443, you can have three different VirtualHosts.
However, you may have to move this logic from htaccess
file to your .conf
file.
Since apache starts finding the matching VirtualHost in the order they are defined in the .conf file (http.conf or apache.conf as the case may be), the ordering is very important.
Upvotes: 0