Does Apache Alias support relative paths?

Solution 1:

You can use a relative directory-path (or file-path) as the target of the Alias directive. However, it is relative to the ServerRoot, not the DocumentRoot.

One of the main uses of the Alias directive is to be able to access files outside of the current DocumentRoot, so it wouldn't necessarily be logical to have this resolve relative to the DocumentRoot.

If you wanted to "alias" file(s) relative to the DocumentRoot, then you can use mod_rewrite. For example, in a server or virtualhost context:

RewriteEngine On
RewriteRule ^/js/((jquery-1\.9\.1)\.min\.js)$ /lib/$1/$2 [L]

Reference:

  • https://httpd.apache.org/docs/2.4/mod/mod_alias.html#alias
  • https://httpd.apache.org/docs/2.4/mod/core.html#serverroot