Enable apache mod_rewrite for seo user friendly url CentOS 6

Enable apache mod_rewrite for seo user friendly url CentOS 6

The mod_rewrite module on httpd conf is enabled by default on CentOS 6. check if mod_rewrite.so module has been installed and activate at httpd configuration.

#cat /etc/httpd/conf/httpd.conf | grep mod_rewrite
LoadModule rewrite_module modules/mod_rewrite.so

** If it is commented (#), please remove it (#) out.

Enable .htaccess File for seo user friendly
Once the mod_rewrite module has been activated, you can set up your URL rewrites by creating an .htaccess file in your default document root directory.

A .htaccess file allows us to modify our rewrite rules without accessing server configuration files. For this reason, .htaccess is critical to your web server. Before we begin, we need to allow Apache to read .htaccess files located under the /var/www/html directory.

You can do this by editing httpd.conf file:

#vi /etc/httpd/conf/httpd.conf

Find the section <directory /var/www/html> and change AllowOverride None to AllowOverride All, there are 2 AllowOverride Off must change to AllowOverride On

<Directory /var/www/html>
AllowOverride All
</Directory>

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#

Save and exit.

Now restart Apache to put the change into effect:

#service httpd restart

Leave a Reply

Your email address will not be published. Required fields are marked *