Here is a solution that some scenarios can solve when you try to use an alias and rewrite, but cannot, because they conflict.
Suppose your DocumentRoot for a specific application is /var/www/example.com/myapp , and you have the following basic directory structure where public requests are either for files in public (for example, a css file) or otherwise routed through index.php .
myapp/ |- private_library/ |- private_file.php |- private_configs/ |- private_file.php |- public/ |- index.php |- css/ |- styles.css
The goal is to serve content inside public_webroot , however the URL should be example.com/myapp not example.com/myapp/public .
It might seem like it should work:
DocumentRoot /var/www/example.com Alias /myapp /var/www/example.com/myapp/public <Directory /var/www/example.com/myapp/public> # (or in this dir .htaccess) RewriteEngine On RewriteBase /public RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [QSA,PT] </Directory>
But this will lead to an endless loop if you request a URL for a file that does not exist (i.e. one that needs to be routed through index.php ).
One solution is to not use mod_alias, but instead just use mod_rewrite in the root directory of the application, for example:
DocumentRoot /var/www/example.com <Directory /var/www/example.com/myapp> # (or in this dir .htaccess) RewriteEngine On RewriteRule (.*) public/$1 [L] </Directory> <Directory /var/www/example.com/myapp/public> # (or in this dir .htaccess) RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [QSA,L] </Directory>
And it's all!
source share