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”

  1. 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

# mod_rewrite
<IfModule mod_rewrite.c>
# Enable mod_rewrite engine
RewriteEngine on

With the WWW prefix

# Dengan Awalan 'www.'
RewriteCond %{HTTP_HOST} ^$uri\.$tld$ [NC]
RewriteRule ^(.*)$ http://www.$domain$1 [L,R=301]

No WWW Prefix

# Tanpa Awalan 'www.'
RewriteCond %{HTTP_HOST} ^www\.$uri\.$tld$ [NC]
RewriteRule ^(.*)$ http://$domain/$1 [L,R=301]

Restart daemon service apache

root@techsoftcenter ~]# service httpd restart

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