Problems with HTAccess File

Hi there,

I’ve recently been experiencing problems with my website which appear to be related to my .htaccess file.
The main issues are that some pages are redirecting to themselves, while others show a 300 Multiple Choices error page, which only ever has 1 page in the list.

The original setup of my .htaccess file was to both connect up my custom error pages, but also to remove the extension displayed at the end of each page (.e.g. /about.php would appear as /about).

Below is the contents of the current .htaccess file, along with a link to my site.

Options -Indexes

#RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteBase /

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L] 

# Added automatically by Gridhost panel Tuesday 29th of April 2014 07:12:58 PM
ErrorDocument 404 /404.php
ErrorDocument 401 /401.php
ErrorDocument 403 /403.php
ErrorDocument 405 /405.php
ErrorDocument 500 /500.php

DirectoryIndex welcome.html index.html index.htm index.php

I have contacted my website host regarding this, though they were not able to help and advised I post on a forum to find out what is wrong. Please could someone advise?

Cheers,

Andrew

I’ve since adapted the htaccess file to the following but to no avail (checked within Incognito Mode):

Options -Indexes

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

ErrorDocument 404 /404.php
ErrorDocument 401 /401.php
ErrorDocument 403 /403.php
ErrorDocument 405 /405.php
ErrorDocument 500 /500.php

DirectoryIndex welcome.html index.html index.htm index.php

At this point I’m unsure if there is a problem with the host’s server or if it’s something I’ve mistyped in the above…any advice would be much appreciated!

Cheers,

Andrew

I’m not sure what

RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

does or is meant to do, but one way to map documents without an extension is:

RewriteRule ^([a-z0-9-]+)$ $1.php [L]

(provided the document name contains only lowercase letters, numbers and minus signs.)

Thanks for your help Gandalf - that line was originally taken from another forum - it was recommended I use that to remove the .php extension.

I’ve now updated my htaccess as it was recommended elsewhere that I add the options for MultiView and also CheckSpelling off. However, this has now caused all page links to redirect back to the homepage.

Options -Indexes
Options -MultiViews
CheckSpelling off

#RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteBase /

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L] 

# Added automatically by Gridhost panel Tuesday 29th of April 2014 07:12:58 PM
ErrorDocument 404 /404.php
ErrorDocument 401 /401.php
ErrorDocument 403 /403.php
ErrorDocument 405 /405.php
ErrorDocument 500 /500.php

DirectoryIndex welcome.html index.html index.htm index.php

I realised I’d accidentally included a few duplicate lines for the Rewrite Engine and RewriteCond.
However, my pages are still redirecting either to the homepage or a Multiple Choices error.

Options -Indexes
Options -MultiViews
CheckSpelling off

#RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteBase /

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

# Added automatically by Gridhost panel Tuesday 29th of April 2014 07:12:58 PM
ErrorDocument 404 /404.php
ErrorDocument 401 /401.php
ErrorDocument 403 /403.php
ErrorDocument 405 /405.php
ErrorDocument 500 /500.php

DirectoryIndex welcome.html index.html index.htm index.php

Any further thoughts please? :slight_smile:

Cheers!

It looks relatively harmless, but in some cases, depending on the directory structure and file locations, RewriteBase can cause problems. Are you certain you need that directive?

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase

You have two rewrite conditions but no rewrite rules.

1 Like

Thanks for your help, I’ve added the Rewrite Rule back in and also removed the Rewrite Base / line and the URLs without an extension are now working. After testing between the versions it seems that the “Rewrite Base /” line was indeed causing the main issue.

I’m unclear how that line has appeared to be honest as I haven’t touched the htaccess file for quite some time and the site was working up until a few months ago. Either way, it seems I need to learn a bit more about Apache and htaccess!

Thanks again!

Andrew

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.