.htaccess is working
The simplest way to test if apache uses your
.htaccess file, or if it otherwise ignores it, is to intentionally break it.
.htaccess file, so the first line reads ‘Test.’:
Test. # Set the default handler DirectoryIndex index.php index.html index.htm ...
Now, if you refresh the page in your browser, you should see an error page like this:
If you see this error, that’s actually good! This means that Apache is parsing the
.htaccess file, and it encounters the error we’ve put in there! So far, so good!
If you do not see an ‘Internal Server Error’, your Apache setup ignores the
.htaccess file, and you need to fix that. Generally, Apache ignores the
.htaccess file because of the following Apache configuration
AllowOverride none. Check your virtual host configuration and add/amend to
<Directory /var/www/site/example.com/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
mod_rewrite is working
To test if
mod_rewrite is working correctly, do the following:
.htaccessfile with the contents as below.
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^.*$ /redirected </IfModule>
- In your browser, add the URL like
- If the URL is redirected to
http://yourdomain/redirectedit means that the
My htaccess is broken? What do?
There are many reasons why it might not work on your system, and these reasons vary so wildly, that we can’t give an exhaustive solution for that. That said, here are a few pointers that might help you fix it:
.htaccess in your
It’s unusual, but possible that
.htaccess is not enabled on your site. If you are hosting it yourself, it’s easy enough to fix. Open your
apache.conf in a text editor, and locate the
<Directory "/var/www/htdocs"> AllowOverride None
AllowOverride line to:
Be sure to restart Apache after making any modifications to this file. Now, your
.htaccess should work. You can also make this change inside a virtual host, which would normally be preferable, but that depends on the way Apache is set up.
If your site is hosted elsewhere, check your control panel (Plesk, DirectAdmin, CPanel, whatever) to see if you can enable
.htaccess there. If not, contact your hosting provider to do it for you.