Please can anyone help to identify flaw or incompatibility in .htaccess code causing server error?
In the process of changing over from static to dynamic website, I had to maintain some static files with .html
extension, but others were replaced with .php
extension.
Furthermore, I wanted visitors to be able to access any files by file name alone without the extensions. Example: about.html
became about.php
, but index.html
did not change.
I wanted to ensure that browsers would return the correct files even if the uri typed was only http://domain.com/about
or http://domain.com/index
. The following code - implemented some years ago, and I've lost track of the source - has worked perfectly all this while, until today.
# REWRITE FILE URI TO file.php IF EXISTS
Options Indexes +FollowSymLinks +MultiViews
Options +ExecCGI
RewriteEngine on
RewriteBase /
# parse out basename, but remember the fact
RewriteRule ^(.*).html$ $1 [C,E=WasHTML:yes]
# rewrite to document.phtml if exists
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [S=1]
# else reverse the previous basename cutout
RewriteCond %{ENV:WasHTML} ^yes$
RewriteRule ^(.*)$ $1.html
All of a sudden, this block of code is causing a server error. Website is on shared hosting, and I do not have shell access. Server was recently upgraded. Right now my account is running on PHP 5.3.28, Apache 2.4.7. Even after the upgrade last week, everything was still okay. Only today it has ceased to work.
I renamed the .htaccess file and created a fresh file, pasted in fresh code, but sure enough, this bit of code is causing the server to choke. Can anyone point out what might be the problem?
http://domain.com/about
. Presumably this should be rewritten toabout.php
? But theC
(CHAIN) flag in the precedingRewriteRule
would seem to skip the relevant code that does this? Do you need theC
flag? Also,^(.*).html$
should be^(.*)\.html$
- although that is unlikely to be your problem, unless you happen to have other files ending in "<something>html"?# backward compatibility ruleset for # rewriting document.html to document.php # when and only when document.php exists <Directory /var/www/htdocs> RewriteEngine on RewriteBase /var/www/htdocs RewriteCond $1.php -f RewriteCond $1.html !-f RewriteRule ^(.*).html$ $1.php </Directory>
But it does not appear to address the same conditions?