Enable the Apache MOD_REWRITE module for manipulating URLs

The mod_rewrite module in apache is a module that is used to handle URL manipulation and is compiled to the base of the Apache HTTP Server on CentOS.

Following are the steps for configuring Apache mod_rewrite:
1. Open and edit the Apache configuration file which is by default located in “/etc/httpd/conf/httpd.conf


2. Change AllowOverride None to AllowOverride All normally in the <Directory “/ var / www / html”> directory
Example of using mod_rewrite to direct users to access sites “with the www prefix” or “without www prefix”
Open / create a .htaccess file on your public_html page and add the following text or replace the variable with the appropriate values if needed.

Mod_rewrite parameter


With the WWW prefix


No WWW Prefix


Restart daemon service apache

Note:
– Select one of the scripts above (with / without the www prefix)
– Change http: // with https: // if you use the https protocol