The .htaccess file is a configuration file used by Apache web servers to control and override web server configuration settings on a per-directory basis.
It is a plain text file that is usually placed in the root directory of a website or in a specific directory and allows you to configure various settings for that directory, such as authentication, URL redirection, access control, error handling, and more.
To set up the .htaccess file on Apache on CentOS/RHEL, follow these steps:
1. Log in to your server via SSH as the root user or a user with sudo privileges.
2. Navigate to the Apache configuration directory by running the following command:
# cd /etc/httpd/conf/
3. Open the main Apache configuration file httpd.conf in a text editor. You can use nano or vi:
# vi httpd.conf
Look for the AllowOverride directive and change its value from None to All for the directory where you want to enable .htaccess files. For example, if you want to enable .htaccess files for the root directory of your website, you can add the following block of code to the end of the file:
<Directory /var/www/html> AllowOverride All </Directory>
Save the changes and exit the editor.
4. Restart the Apache web server for the changes to take effect:
# systemctl restart httpd