Apache Alias to link to another DocumentRoot
First of all: my pet peeve, quoted from from the manual on .htaccess files:
You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.
Second: the canonical answer to almost all mod_rewrite questions is here
I'm not 100% sure, but I think that by setting the RewriteBase to /
the internal redirect as you have it will be to example.com/index.php and not to /var/www/project/index.php. Additionally I think the PT flag is required to take into account the Alias matching.
You may want to try
Alias /admin/ /var/www/project
Alias /client/ /var/www/project
<Directory /var/www/project>
RewriteEngine On
RewriteBase /
# Do nothing when a file or directory with the requested name exists
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]
# Use the request URL to select the correct module and task
RewriteRule ^/([^/]+)/(.*)$ /$1/index.php?module=$1&task=$2 [PT,L,QSA]
</Directory>
Related videos on Youtube
Aley
Updated on September 18, 2022Comments
-
Aley over 1 year
I have a WordPress installed in
/var/www/wordpress/
and my own code in/var/www/project/
Now comes the following problem: When I try to access
example.com/client/
orexample.com/admin/
it should link to/var/www/project/
and execute the .htaccess + index.php from there.I have tried to place an Alias directive in the Apache config with partial success.
Alias /admin/ /var/www/project Alias /client/ /var/www/project
When I access
example.com/client/
it works fine, but as soon as I requestexample.com/client/login
it failes withFile does not exist: /var/www/project/login
error.The
.htaccess
in/var/www/project
looks likeRewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/(.*)$ index.php?module=$1&task=$2 [L,QSA]