Search code examples
apachehttp-redirectvirtualhosthttpd.confmod-alias

Does the Redirect directive override configured Aliases


I'm setting up apache 2.4 (docker) as a reverse-proxy to distribute different subdomains to different docker services. I redirect http-requests to https using the Redirect directive. One specific URL-path (the part after the domain), however, should not be redicted to https, but served with files from a specific directory. I'm trying to accomplish this using the Alias directive, which does not work.

I'm assuming that Redirect overrides Alias. Is that true? And how could I accomplish my goal if this is the case?

<VirtualHost *:80>

    ServerName service.example.com

    Alias /exception/ /var/www/exception
    Redirect permanent / https://service.example.com/

</VirtualHost>

I expected this to work, but it does not.


Solution

  • From mod_alias docs:

    First, all Redirects are processed before Aliases are processed, and therefore a request that matches a Redirect or RedirectMatch will never have Aliases applied. Second, the Aliases and Redirects are processed in the order they appear in the configuration files, with the first match taking precedence.

    To make sure that /exception/ is not matched, use RedirectMatch which allows regex patterns:

    RedirectMatch permanent "^/(?!exception/)(.*)" "https://service.example.com/$1"