How to Set AllowOverride All in Apache


how to set allowoverride all in apache

When you run a website on Apache, you might need to customize it according to your own requirement. It can be tedious and error-prone to modify its server config file every time. So Apache provides a useful AllowOverride directive that allows you to override its default configuration without modifying its config file. This allows you to make config changes via other files such as .htaccess. Let us take a look at how to Set AllowOverride All in Apache.

 

How to Set AllowOverride All in Apache

AllowOverride directive allows you to override Apache settings in its configuration file. It is valid only in <Directory> sections.

Here are the steps to set AllowOverride All in Apache.

 

Let’s say you want to be able to modify Apache configuration using .htaccess file, without modifying its server config file.

In that case, follow these steps

1. Open Apache config file

Open a terminal session or SSH into your Linux system, and run the following command to open Apache config file

You will find it at one of the following locations, depending on your Linux system:

  • /etc/apache2/httpd.conf
  • /etc/apache2/apache2.conf
  • /etc/httpd/httpd.conf
  • /etc/httpd/conf/httpd.conf

 


$ sudo vim /etc/apache2/apache2.conf

 

2. Add AllowOverride All

Change the following block of code


<Directory /var/www/>
 Options Indexes FollowSymLinks
 AllowOverride None
 Require all granted
</Directory>

 

to


<Directory /var/www/>
 Options Indexes FollowSymLinks
 AllowOverride All
 Require all granted
</Directory>

 

The above code will allow other files like .htaccess to override server configuration mentioned in the config file. Since it is applicable to Document Root /var/www/, it will be applicable to your entire website.

If you want to restrict AllowOverride to a specific directory (e.g wp-admin), then you can specify it in the directory block.


<Directory /wp-admin/>
 Options Indexes FollowSymLinks
 AllowOverride All
 Require all granted
</Directory>

 

 

3. Enable mod_rewrite


$ sudo a2enmod rewrite

 

 

4. Restart Apache Web Server

Restart Apache web server to apply changes


$ sudo /etc/init.d/apache2 start [Debian or Ubuntu]
# sudo apachectl restart [RHEL, CentOS or Fedora]

 

 

 

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!