1. Startseite
  2. Web-Inhalt
  3. Rewrite rules fail on subdirectories, subdomains, or addon domains

Rewrite rules fail on subdirectories, subdomains, or addon domains

Übersicht

Rewrite rules remap a URL to another location or resource accessible on a web site. These rules are located in .htaccess files. A common snippet looks similar to:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} ! -f
RewriteRule ^(.*)$ index.php [QSA, L]

When located anywhere else besides the Dokumentenstamm of the primary domain name, rewrite rules will fail yielding an Internal Server Error.

Ursache

Rewrite rules modify the URL relative to a document root defined in the web server configuration as DocumentRoot. Each site may have one DocumentRoot defined and this value is always /var/www/html. Additional domains, subdomains, and resources located under /var/www/html are subject to filesystem remaps outside the location of DocumentRoot. RewriteBase is necessary to anchor a rule set to the new filesystem location.

Lösung

Inside the .htaccess, immediately following RewriteEngine On, add RewriteBase / or if the .htaccess resides under a subdirectory that also appears in the URL path, then use that directory in the URL path, e.g. http://example.com/mysubsite .htaccess rewrite rules would require RewriteBase /mysubsite as opposed to RewriteBase /.

A revised example of the earlier snippet would read as follows:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} ! -f
RewriteRule ^(.*)$ index.php [QSA, L]
Aktualisiert am März 7, 2021

Verwandte Artikel