5

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]

1 Answer 1

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.

2
  • 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 Commented Oct 19, 2015 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. Commented Oct 19, 2015 at 12:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.