Apache Alias For External Directory And All Sub Directories

1.9k Views Asked by At

I want to add a alias for my website. So that website.com/alias will go to a folder outside of the root folder. This folder contains a different website so i want to be able to treat this alias as if it were a subdomain.

AliasMatch  ^/subdir1/(.*)$ /var/www/otherfolder/subdir1/$1

I was hoping this would match all calls, so that website.com/subdir1/css/style.css would also be a valid path, but all of these are returning 404 errors.

How can i make the alias match a wildcard so that the entry will cover all subdirectories in the alias folder. I want to be able to do this on the apache level rather than having to do it within the .htaccess file because things are already quite complicated there so i want to bypass it if possible.

2

There are 2 best solutions below

0
On BEST ANSWER

The issue was caused by a base URL. "/" was not correctly working as a base url. Instead i was able to solve it based on the answer here.

Set RewriteBase to the current folder path dynamically

RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]

The above was enough to solve the problem based on the post i have linked.

3
On

Aliases will work if you have mod_alias.so http module loaded. You need to edit httpd.conf configuration file and add below line and restart httpd.

LoadModule alias_module modules/mod_alias.so