2

Brand new to apache, using 2.4 in this case, trying to get a redirect rule to work such that everything on port 80 is redirected to 443, except certain routes.

This rule keeps redirecting everything even the path i specified.

<VirtualHost *:80>
        ServerName some-name
        ServerAdmin some-name
        UseCanonicalName on
        RewriteEngine On
        RewriteCond "%{REQUEST_URI}" "! /server-status/*"
        RewriteCond %{SERVER_PORT} !443
        RewriteRule ^(.*)$ https://some-name$1 [R]
</VirtualHost>

1 Answer 1

2

You need modify the RewriteCond, this because the REQUEST_URI includes everything after and including the forward slash.

Example:

http://www.example.com/server-status/
REQUEST_URI = /server-status/

The ^ mean defines that the patter must start at beginning of a new line and .* finds any character sequence.

<VirtualHost *:80>
        ServerName some-name
        ServerAdmin some-name
        UseCanonicalName on
        RewriteEngine On

        # Modify this line
        RewriteCond "%{REQUEST_URI}" "!^/server-status/.*"

        # You can remove this line           
        # RewriteCond %{SERVER_PORT} !443

        RewriteRule ^(.*)$ https://some-name$1 [R]
</VirtualHost>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .