Contents...
In this article we will learn how to debug .htaccess log in Apache .htaccess file is a Apache configuration file which is used on running Apache web server software. If we create .htaccess file in web root directory then this file is detected and executed by the Apache web server. It is used to alter the Apache configuration. It is used to enable/disable additional functionality and features. This facilities include basic redirect functionality, for example if a 404 found on the site. This is also used to secure content using password protected or image hot linking prevention.
.htaccess also allow users to override the Apache global and virtual host setting.
If your .htaccess defined rules is not working you should check apache configuration file if it is allowed to read your .htaccess file or not. If this is not working after enabling it in apache config you should also check the Apache rewrite module is enabled or not.
In this article I will explain you how to debug .htaccess file is working or not.
Verify Enable Modules in Apache
First of all check enable modules which you want to set in .htaccess file. Run this below command to check the all apache enabled or loaded module.
For Ubuntu or Debian system:
$ apache2ctl -M Loaded Modules: core_module (static) so_module (static) watchdog_module (static) http_module (static) log_config_module (static) logio_module (static) version_module (static) unixd_module (static) access_compat_module (shared) ...
If above command not working on your system you can also try this below command:
$ apache2ctl -t -D DUMP_MODULES
In CentOS/Redhat Unix system
$ apachectl -t -D DUMP_MODULES
OR
$ httpd -M
Check specific enabled module in apache
Above command print the all enabled module in Apache but if want to check specific enabled module you can run this below command.
For example, I am checking Apache rewrite module.
Ubuntu or Debian
# apache2ctl -M | grep rewrite rewrite_module (shared)
CentOS/Redhat or UNIX
# httpd -M | grep rewrite rewrite_module (shared)
Verify .htaccess file is allowed in Apache configuration or not
If all modules is enable now check Apache configuration file if it is allowed to read .htaccess file or not.
Check your default Apache config file which is located on /etc/httpd/httpd.conf and find the “Allowoverride” line and if it is set to “none” your .htaccess file will be ignored by apache. It means your .htaccess files rules will not work. It will be set like below:
Allowoverride none
Now if it is set to “none” you have to change this options to “all” like below:
Allowoverride all
That’s all.
I hope this steps will help you to solve your .htaccess not working issue.
You should also learn : how to enable .htaccess file for Vhost in Apache?
FAQs
What is .htaccess file?
.htaccess file is a Apache configuration file which is used on running Apache web server software. If we create .htaccess file in web root directory then this file is detected and executed by the Apache web server.
How to create .htaccess file?
To create a .htaccess file in linux you can use vim/vi or nano editor to create a file. Select path where you want to create it and past this below line in your .htaccess file and save it.
RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]
What is .htaccess file in WordPress?
If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.
Leave a Comment