4.2
(100)

Last Updated on March 3, 2022 by Amit

Is htaccess working on apache
Do you want to know whether the htaccess file is working or not working on your Apache server?
In this article today, I will show you how to verify whether the htaccess is being read by your server. For many new Apache users who are beginners in htaccess and URL rewriting this can be a bit complicated to know if the htaccess they are using is working so I decided to write this Article to help them.

How to know wether your htaccess is working on Apache server.

An htaccess file on apache server uses .htaccess extension by default. The file doesn’t have name just the the extension. The first thing you need to make sure is that the file name is exactly . htaccess . If it is misspelt then correct it because many new user when they create an htaccess file they either misspell the name or create file name as htaccess.txt . The correct name that the server knows of this file is .htaccess .
Also there are multiple ways to check whether your server is reading the .htaccess. There are many ways to check it but here I will include only the ones that will help you at beginner level.

The quick , easy and effective way to check wether your server is reading the htaccess file is by adding a Redirect to your htaccess file.
Open your htaccess file for writing in an editor and put the following line at the top of your htaccess :

Redirect /foobar/ https://example.com

Save the file and type the URL yoursite.com/foobar/ .
If the reditect works and the URL gets redireted to the homepage of example.com then it’s clear that your htaccess is working and being read by your Apache server.
If it still doesn’t work then the problem might be that your hosting provider has not enabled it. In that case you could ask your hosting service provider to enable it for you.

Another way to check htaccess :

You can also check your htaccess by using RewriteRule directive .
Add the following rule to your htaccess :

RewriteEngine on
RewriteRule ^foobar/$ https://example.com/ [R]

I suggest you to try this if the first method fails. Sometimes Redirect directive doesn’t work as it gets overridden by other directives, RewriteRule never fails to work , so you can try this one if the the above fails and if it also fails then ask your hosting provider.

How to check if mod_rewrite is enabled on my server

If htaccess is enabled on your server but you are unsure wether your hosting server has mod_rewrite enabled or not then you can follow the following steps to check it. Mod_rewrite is an Apache module that allows us to use RewriteRule in htaccess to rewrite URLs.
To check if mod_rewrite is enabled , do the following simple thing :
Add some random texts eg. asdfghjkl to your htaccess file. And then visit your site. If you get a 500 internal server error it means that the module is enabled otherwise if you don’t see any error and the site loads fine then you will need to enable it. If you are using shared hosting or don’t have much knowledge as to how to enable this module , just ask your hosting provider to do this . If you can do this yourself then just open the server.config file and change this line

Allow override none

To

Allow override All

This will enable the module and then you can use RewriteRule directive .

How useful was this post?

Click on a star to rate it!

Average rating 4.2 / 5. Vote count: 100

No votes so far! Be the first to rate this post.