Check .htaccess is working or not on server !

Previously I wrote Rewriting tips using .htaccess file for URL rewriting.

Common Usage of .htaccess file :
– Authorization, authentication
– Rewriting URLs
– Blocking
– Directory listing
– MIME types
– Cache Control, and many more.

Here is a test to check that .htaccess or mod_rewrite is enabled on any type of hosting whether shared or dedicated.

Now we want to check for mod_rewrite is enabled or not.

1- First of all create an empty file and name it test.html (or what you want) and upload this file on you hosting server.

2- Create a .htaccess file and put the following code into it. (create htaccess.txt file )

RewriteEngine On
Options +FollowSymLinks
RewriteRule ^test\.html [R=301,L]

Note: On windows machine first create htaccess.txt file, then adds the above code into it, upload on server, after uploading remove the .txt extension.

3- Now run this URL into your browser (replace with your actual domain name).

If it redirects you on then mod_rewrite is working on your server host, if it is not, shows you a blank file means mod_rewrite is not working.

4- If your site runs in some folder then adds the folder name before test.html and uploads the htaccess file in the root folder. Eg

RewriteEngine On
Options +FollowSymLinks
RewriteRule ^foldername/test\.html [R=301,L]

Author: Dheeraj Dhawan

I'm a web developer / PHP programmer. I am also working on custom plugin development of wordpress.

5 thoughts on “Check .htaccess is working or not on server !”

  1. Thanks for the article. I followed your suggestion, but my test.html is not rediercted to I have restarted the apache service, using the command sudo service httpd restart. Then how to enable or make .htaccess to work on my site.

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

      For example,

      httpd.conf before:

      Options FollowSymLinks
      AllowOverride None

      httpd.conf after:

      Options FollowSymLinks
      AllowOverride All

      1. Thank you Amerandra. I have been struggling for some time to get mod_rewrite in apache to work, so that BuddyPress and WordPress would work. I had a case of the dreaded 404 for all BuddyPress links. I finallly determined that my .htaccess file was not being used. But I still didn’t know why! mod_rewrite was enabled so that was not it.

        AllowOverride All was the key variable I needed. Ah, sweet success.

Leave a Reply

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