Skip to main content

htaccess rules not taken (some rules but not all) (How to Fix)

The hierarchy of the .htaccess files is taken from

1)    Apache htdocs folder (/var/www/html)
2)    Local Webserver root folder (let us say website)

If your htaccess is present in the Local Webserver root folder (website) and all the changes are not being taken or some changes are taken but not all the rules are taken

1) Go a step above the Local Webserver root folder (website) and see if there is any other .htaccess file

2) Backup the .htaccess file to another folder (not in the path of the website folders. Preferably outside the webserver folders) 

3) Check if the rule changes are working

4) If it is working – the reason could be that apache is merging the rules from the .htaccess file a folder above and your website’s .htaccess folder, giving precedence to the first .htaccess file. 

This is an error in configuration of your Document Root. Check document root. 

By default, it would be /var/www/html but most sysadmin change the path to a custom directory

To find out your current DocumentRoot (CENTOS/RedHat versions), login as root

grep -i 'DocumentRoot' /etc/httpd/conf/httpd.conf
grep -i 'DocumentRoot' /etc/httpd/conf.d/ssl.conf

If your DocumentRoot is /folder_above/website, change it to /website

Changing in httpd.conf

<VirtualHost *:80>
  ...
  DocumentRoot /website
</VirtualHost>


Changing in ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
 ...
  ....
  DocumentRoot /website
  
</VirtualHost>
</IfModule>

Restart your apache server
* website is your website’s complete folder path
* path of the VirtualHost files will vary if you are on a hosted service

 

 

Technical