Mobile app version of vmapp.org
Login or Join
Martha676

: Changing file extensions in URIs - Server Error after Apache upgrade Please can anyone help to identify flaw or incompatibility in .htaccess code causing server error? In the process of changing

@Martha676

Posted in: #Htaccess #ModRewrite #UrlRewriting

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 domain.com/about or 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$ [C,E=WasHTML:yes]
# rewrite to document.phtml if exists
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ .php [S=1]
# else reverse the previous basename cutout
RewriteCond %{ENV:WasHTML} ^yes$
RewriteRule ^(.*)$ .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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Martha676

1 Comments

Sorted by latest first Latest Oldest Best

 

@Alves908

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme