The Six Most Common Htaccess Problems and How to Fix Them

Is your Apache htaccess not working? Here are the top reasons why an htaccess file may not work, and how get your htaccess working.

Htaccess Problem #1: No Dot Before the Filename

The .htaccess file’s filename must start with a dot, like so:


Files and directory names starting with a dot are treated as hidden files by Unix, Linux & Mac. The htaccess file is hidden so it doesn’t distract from normal web content like HTML files. See hidden files for more information.

Without the dot at the beginning, Apache will ignore the htaccess file.

Htaccess Problem #2: Filename Not All Lowercase

If an htaccess file’s name contains uppercase letters, it generally will not work on Linux or Unix. This is because filenames on Linux and Unix are usually case sensitive. If an htaccess file has any uppercase letters, e.g. .HTACCESS or .HTaccess, Apache won’t find the htaccess file. The htaccess is ignored.

An htaccess file containing uppercase letters generall will work on Windows and Mac. This is because filenames on these platforms are generally case insensitive. I’d recommend sticking with lowercase, so your websites are portable to Linux servers. The use of uppercase letters could also circumvent Apache directives designed to prevent the contents of .htaccess files read from the web.

Htaccess Problem #3: Filename Misspelt

Common misspellings of the htaccess file’s name are htacess and htacess. Check the filename has two c’s and two s’s.

Htaccess Problem #4: Htaccess Disabled by AllowOverride Setting

On some servers, Apache is configured to ignore some or all directives in .htaccess files. This is for security reasons. The AllowOverride directive controls which features will be allowed in .htaccess files. For example AllowOverride None can turn off htaccess files for a folder and its subfolders.

Check your Apache configuration file for which AllowOverride directive is applied to the directory containing your problem htaccess file.

If you’re not sure which configuration file to look in, start with the main Apache configuration file httpd.conf or apache2.conf. If your website is configured in a file included by httpd.conf (e.g. a virtual hosts configuration file), you will need to look in that file. See Location of httpd.conf on CentOS, Ubuntu, Mac and others to locate your httpd.conf.

To enable using a .htaccess file, change AllowOverride None to AllowOverride All.

For example, for a CentOS 5.3 server, I needed to change the AllowOverride setting in the file /etc/httpd/conf.d/virtualhosts.conf.

httpd.conf before:

Options FollowSymLinks
AllowOverride None

httpd.conf after:

Options FollowSymLinks
AllowOverride All

Be aware that enabling htaccess files has security implications, as htaccess files override your Apache configuration. For example, if your site provides uploads, a hacker could potentially upload a .htaccess file to your server and use it to gain access to your server. There are options to AllowOverride that restrict the directives that will be used from a .htaccess file. See the documentation for AllowOverride.

Htaccess Problem #5: Incorrect Syntax

If Apache can’t understand a line in your htaccess, it will usually cause an error from Apache. The error may show in the web browser when a webpage causes Apache to read the .htaccess file.

To demonstrate this, I added a bad line to the Smart Web Developer .htaccess file. See if you can spot the bad line. :-)

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
utter rubbish config line here

This causes the following error in the browser:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

The reason for the error is logged to an Apache error log:

[Sat Feb 26 18:21:09 2011] [alert] [client] /Users/taz/Sites/smartwebdeveloper/.htaccess: Invalid command 'utter', perhaps misspelled or defined by a module not included in the server configuration, referer:

Another option to debug Apache syntax is to put the the .htaccess contents into the main Apache configuration file under a <Directory> directive. Apache has an option to parse and check its configuration files. To run an Apache syntax check, run: httpd -S.

Htaccess Problem #6: Htaccess Settings Overridden by Another Htaccess File

Multiple .htaccess files may be read and applied if a web request is made to a file in nested directories. Typically all .htaccess files in the path between the website’s root directory and the requested file’s directory will be read and applied in order. As a result, an htaccess file in a more deeply nested directory can override the settings made by an htaccess in a higher directory.

Is there another .htaccess file in another directory in the path to your webpage? That htaccess file the may be overriding the settings in the htaccess you’re looking at.

On Mac, Linux & Unix, you can find all .htaccess files on your website in the terminal:

find /path/to/website/root -iname .htaccess -print


Hope this article helped you! If it did, write me a comment and let me know.

Tagged , . Bookmark the permalink.

15 Responses to The Six Most Common Htaccess Problems and How to Fix Them

  1. Pingback: Redirect www to Non-www Domain Using Apache .htaccess File « Smart Web Developer

  2. Chris Were says:

    Thanks alot. Still having problems with .htaccess but at least I know it’s not one of those errors.

    Thanks for the post!


  3. Ravikumar says:

    hi…i created one .htaccess file.It is working fine in the local system but if i hosted in server it is not working.please tell me what is the problem

    Here my .htaccess code

    RewriteEngine On
    RewriteRule ^cinemas$ movie.php
    RewriteRule ^tourismplaces/(.*)/?$ tourism_detailpage.php?id=$1 [L]

  4. Ravikumar says:

    This is my .htaccess file

    RewriteEngine On

    RewriteRule ^([a-zA-Z0-9_-\s]+)$ tourism_detailpage.php?id=$1
    RewriteRule ^([a-zA-Z0-9_-\s]+)/$ tourism_detailpage.php?id=$1

  5. Ravikumar says:

    Yes i gone through the six items what you explain…But still it is not working

  6. Remya says:

    For gzip compression , i was added a line “php_value auto_prepend_file prepend.php
    ” in .htaccess. It was working well in localsystem, when it is hosted it showing 500 internal server error. Please Tell me what is the problem

  7. Jitendra Meena says:
  8. Mousepad says:

    I have been configuring Apache servers for almost two years now. I still couldn’t figure out why my htaccess file wasn’t working, until I remembered that I had set AllowOverride to none when enabling Perl on one of my virtual hosts. This article really helped!

  9. haresh says:

    here is my .htaccess code it works on localhost…but it does not work in server..pls help me
    RewriteEngine on
    RewriteRule ^home$ index.php
    RewriteRule ^login$ login.php
    RewriteRule ^menu\/(.+)$ menu.php?type=$1
    RewriteRule ^recipe\/(.+)$ details.php?id=$1
    RewriteRule ^print\/(.+)$ print_recipe.php?id=$1
    RewriteRule ^search/(.+)$ search_data.php?q=$1
    RewriteRule ^contact$ contact.php
    RewriteRule ^watchlist$ my_watch.php
    RewriteRule ^logout$ logout.php

Leave a Reply

Your email address will not be published. Required fields are marked *