Mod-rewrite rule broken after host upgrade to Apache 2.4

Mod-rewrite rule broken after host upgrade to Apache 2.4 - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about apache2, php, htaccess, mod-rewrite, .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I use the following code on my site to remove php extension from links:



RewriteEngine On
RewriteBase /
RewriteCond %HTTP_HOST ^www.(.+)$ [NC]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]


It was working fine, but my host GoDaddy upgraded their servers to Apache 2.4 and now all links return 404. How to correct this ?


Solution :

You may want to also shut off fastCGI with these in the .htaccess file



AddHandler x-httpd-php5-cgi .php
AddHandler x-httpd-php5-cgi .php5


Solution:



Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## don't touch /forum URIs
RewriteRule ^forums/ - [L,NC]

## hide .php extension snippet

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %THE_REQUEST ^[A-Z]3,s([^.]+).php [NC]
RewriteRule ^ %1 [R,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %REQUEST_FILENAME !-d
RewriteCond %REQUEST_FILENAME.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

# To remove www header
RewriteCond %HTTP_HOST ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]

Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect