Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using the following mod_rewrite rule in apache config to force all traffic through https:

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

This is working great when I access the server from inside the same network. When I access it externally, the rewrite doesn't take place and it doesn't change to https. I'm using the same url to access it in both cases.

Any idea why this is happening and what can be done about it?

EDIT: I can't answer my own question yet because of my low reputation, but I found the issue:

Solution

This server needs to be PCI compliant, so it turns out the firewall I'm behind blocks port 80 entirely. That means the request never even makes it far enough to do the re-write when coming from the outside.

That means you have to request https to begin with since I can't forward it. (Maybe I can see if I can have the firewall do this, but that's a separate issue.)

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I think you want the RewriteCond to be based on server port:

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

EDIT:

Nevertheless, you've determined that the rule isn't the problem.

Turn on your RewriteLog in either your apache config file or your vhost config and see what mod_rewrite is up to.

Also, provide the output of iptables -L

share|improve this answer
    
This is actually the rule I had first. Same thing with this one. Works from inside but not outside. It makes it seem like some other setting is interfering. –  William W Apr 16 '12 at 23:03
    
@William Thanks for the update. I've updated my answer. –  Wesley Apr 16 '12 at 23:10
    
@William Where is the rule configured? –  Shane Madden Apr 16 '12 at 23:19
    
@WesleyDavid That second rule seems a bit wacky ;) –  Shane Madden Apr 16 '12 at 23:20
    
The RewriteLog has the successful rewrite from my internal attempt. There is not even a single entry from the external attempt. Also, here is the server's iptables -L output: pastebin.com/uF4mSeuh –  William W Apr 16 '12 at 23:23
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.