2

I have a Centos 6.7 with apache 2.2.15. I want to redirect all traffic from port 80 to 443 with one exception. The traffic who come from localhost I want to remain on port 80.

Now I use this config but I don't know how to change it

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]
3

You need to use a RewriteCond with %{REMOTE_ADDR}, possibly multiple to deal with if you have IPv6 enabled or not. This is the basic config:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]

Here is a tutorial on using RewriteCond that might be some help.

  • Thanks! It's work but only for request like this http:// localhost. If the request is like this http:// 127.0.0.1 doesn't work. How can I solve this? Thanks – antiks Oct 19 '15 at 7:46
  • As I said you may need to add a few RemoteConds to deal with all cases. The way to see why specific cases are not working is using an Apache log file with LogFormat containing the vars you are using in your conditions, or write some server content in PHP (or whatever your preferred server side tech is) that outputs what the variables are for a specific request. – DanSut Oct 19 '15 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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