Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

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?

share|improve this question
What has happened between the "upgrade last week" and today? What "server error" are you getting? Just the ol' "500 Internal Server Error"? Do your error logs report anything? –  w3d Feb 25 at 17:19
I may have missed something, but I can't see see how this code handles the situation when the user types http://domain.com/about. Presumably this should be rewritten to about.php? But the C (CHAIN) flag in the preceding RewriteRule would seem to skip the relevant code that does this? Do you need the C 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"? –  w3d Feb 25 at 17:53
Thank you, w3d. Error log shows "[Tue Feb 25 16:34:38.229893 2014] [core:alert] [pid 485480] [client] /home/harekris/public_html/.htaccess: Either all Options must start with + or -, or no Option may." –  chankirtan Feb 25 at 18:49
The rule set above originally posted at [httpd.apache.org...] by Engelschall, December 1997, for Apache httpd v 2.0. The guide for Apache httpd v 2.4 at [httpd.apache.org...] gives new rule set: # 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? –  chankirtan Feb 25 at 18:53
I've answered with what I think should cover your immediate problem. As regards the rest of your code, you can add that to your question - this should preserve the formatting. –  w3d Feb 25 at 19:45
add comment

1 Answer 1

up vote 2 down vote accepted

Either all Options must start with + or -, or no Option may.

Ah yes! This behaviour has changed with the move to Apache 2.4 - it has always been invalid - but now "will be rejected during server startup by the syntax check with an abort." Reference: Apache Docs

You need to specify a + before the Indexes option:

Options +Indexes +FollowSymLinks +MultiViews
share|improve this answer
Well, I tried to upvote your reply, which is after all the answer to the problem with the server error. : ) But evidently I don't have enough points to upvote. : ( Thank you. Nonetheless, the rules now do not work as they did work on this site just 24 hours ago and as they are working beautifully on another site right now. I'm checking with host to see what might have happened to the server configuration in the last 24 - 48 hours. –  chankirtan Feb 25 at 20:13
Yes (unfortunately) you need 15+ points before you can upvote. However, you can mark it as "accepted" (by clicking on the tick) - but you might have to wait a short while before you can do that. Post back when you hear back from the host. –  w3d Feb 25 at 20:20
Host support says no changes have been made. Server settings for PHP5.3 are host's default settings - see link[/link]. Objectives: serve foo.php where exists; else foo.html; also serve domain.com/foo upon request. –  chankirtan Feb 26 at 0:51
Well well well. Turns out to be a case of poor proofreading on my part. Forgot to substitute .php for .phtml in the RewriteRule. How embarrassing. Now all is well. Except that host says nothing changed in last 24-48 hrs on server, so who knows why the error appeared only yesterday. But thank you again, it's working as it ought. : ) –  chankirtan Feb 26 at 1:11
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.