0

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>
0

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>

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.