Apache Alias directive – not ignore .htaccess files

.htaccessapache-2.2apache-2.4mod-alias

When using the Alias directive to map a URL to a directory outside the document root, it seems that the .htaccess files in the document root are not applied to those requests.

For example, if setting php_flag display_errors off in /home/user/document_root/.htaccess, but accessing www.example.com/aliased_url/phpinfo.php, display_errors will be 'on' if that's what the global PHP setting is and it won't get overridden like www.example.com/phpinfo.php has it.

Is there some way to alter this behavior (or accomplish this) without doing symbolic links instead?

EDIT Feb 13, 2016:

The goal is to create a phpinfo file that works for all sites to display the effective configuration of that particular site (which can be affected by open source CMSes which use an htaccess to modify php.ini values).

Best Answer

By design .htaccess files indeed only effect Apache's behavior based on which location in your file-system is used to serve a request.

When you want to change settings for a specific VirtualHost or based on URL Location you will need follow what is best practice anyway and move your configuration directives to the actual Apache configuration file (and disallow .htaccess files completely).

In this case that will solve your problem because you're no longer dependent on a filesystem location for your directive to take effect...

<VirtualHost *:80>
  ServerName    www.example.com
  ServerAlias   example.com
  DocumentRoot  /var/www/example.com/
  Alias /scripts/ /var/www/scripts/
  php_flag display_errors off
</VirtualHost>

If you're not the system administrator and don't have access your Apache config, well, your question wouldn't be on topic but that's beside the point, you can only solve the issue by creating a (copy) .htaccess file in the Alias directory. Depending on the AllowOverride directive the real administrator configured for you, you normally are allowed to place .htaccess file in any directory and subdirectory Apache has access to. You're not restricted to the DocumentRoot.

Related Topic