How to Enable Mod-Rewrite Module?
By Aslam Saah
You can enable mod_rewrite by adding the following line in the .htaccess file of your website.
RewriteEngine On
You can customize the rules below this rule based on your requirement.
For example, I have provided you the rules for force Http to Https redirection through .htaccess which is added below RewriteEngine rule.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Content Management System like WordPress by default will have RewriteEngine ON in their .htaccess file. Below you can see the default .htaccess file of WordPress. If you would like to add the above https redirection line, then you can add it before # END WordPress
# BEGIN WordPress
RewriteEngine On
RewriteBase / RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
How To View and Edit .Htaccess in cPanel:
- Login to cPanel
- Select “File Manager” Option
- Click on “Settings” on the right top corner of your cPanel interface.
- Select the Checkbox “Show Hidden Files (dotfiles)” to view .htaccess file.
- Right Click on .htaccess file and use the edit option to do modification in the file.
[Tweet “How to Enable Mod-Rewrite Module?”]