How to enable mod_rewrite in cPanel

Last Update:

Reviewed by Durr E Adan

This post contains affiliate links, and we will be compensated if you buy after clicking on our links.

Read our review guidelines

Want to turn your rewrite engine on? Confused about how to enable mod_rewrite in cPanel?

Here’s a step-by-step guide to enable it. We have covered multiple ways to enable mod_rewrite in your server. Lastly, the guide also covers various ways to check it.

Let’s start. How to enable mod_rewrite in cPanel

What will you need to enable the rewrite module?

Let’s see what you will need to get started.

  • Access to cPanel: It goes without saying, you will need access to your cPanel.
  • Apache web server: Mod_rewrite is an Apache module. So, your hosting will need an Apache server. You don’t need to worry as most of the cPanel runs on Apache servers only.
  • Mod_rewrite status: It’s recommended to check if mod_rewrite is enabled by default in your hosting providers. The “Apache status” section in your cPanel allows you to check the same. You can also contact the hosting provider and ask them directly.
  • Ability to Edit .htaccess File: The majority of servers already have it. You can do it via file manager or FTP. So, you don’t need to worry about this one.

editing htaccess file

How to enable mod_rewrite in cPanel?

Follow all steps carefully to enable mod_rewrite in cPanel.

Step 1: Head over to the file manager from cPanel

The first step is to head over to your cPanel and log in to your account. Once you do it, you can simply navigate to the file manager.

navigating to cpanels file manager

Now, simply head over to the “Public_html” folder or your website’s directory.

Step 2: Open .htaccess file

Your next step is to open the .htaccess file.

If you don’t see the .htaccess file in the public_html folder, you can head over to “Settings” in the top-right corner and check the “Show hidden files” box.

cpanel settings showing hidden files

This will start showing up many files along with .htaccess. Right-click on .htaccess and click on edit.

htaccess file editing

Step 3: Enable Mod_rewrite

There are two options here, either your .htaccess file will have some data or it will be completely empty.

In first option, see if .htaccess file has some data, you can look for “Rewrite_engine” and replace “no” with “yes”.

enabling mod rewrite via htaccess

The 2nd option is where the complete file is blank. In that case, you simply need to write the same line of code in it.

RewriteEngine On 

Just type in the above line and save the changes, make sure the color changes to ensure that it’s entered properly.

Save the file, and close the tab.

That’s it, you have successfully enabled mod_rewrite.

Now that you know steps for enabling mod_rewrite in cPanel, we will see how you can check the same.

How do I know if mod_rewrite is enabled?

There are multiple ways to check if mod_rewrite is enabled on your server or not. You can try any one of these methods which you can easiest.

1. Using .htaccess File:

There are multiple ways to test if the rewrite engine is ON from the .htaccess file. As mentioned in the above section, you may have already created a .htaccess file with a line that says RewriteEngine On. Now, you need to add one more line below it.

RewriteRule ^.*$ – [L,R=200]

The rewrite rule will give a response code of 200 to all the URLs without actually redirecting the websites.

You can open the website again and hit “F12” on your keyword which will open the developer’s tools. Click on “Network” and reload the website again. It will show you a status code of 200 which means the rewrite rule is successfully enabled.

checking mod rewrite status

2. Checking Apache Configuration Files

Check out apache configuration files if you have access to them. The file is called httpd.conf or apache2.conf. Make sure you also check on all the sub-configuration files.

If you don’t have direct access to it, you can use the following command lines in the Linux terminal.

Type in the following line to open the config file of apache.

sudo nano /etc/apache2/apache2.conf

apache2 editing configuration file

It will open the file in the file editor. You can find the following line of code.

LoadModule rewrite_module modules/mod_rewrite.so

You can use Ctrl+F to find the line in the code.

3. Using PHPInfo()

Create a new PHP file in your web server with the following code.

<?php

phpinfo();

?>

Open the PHP file from your URL http://yourdomain.com/info.php.

Look for sections of Apache Environment or apache2handler and see if it has mod_rewrite as a loaded module or not.

confirm loaded modules via phpinfo

4. Command Line (On Linux)

Open the terminal and type in the following line.

apache2ctl -M | grep rewrite

If you see the output as rewrite_module (shared) or it’s simply written rewrite_module, it means that your mod_rewrite module is enabled. If you don’t see any output, it means your mod_rewrite output is disabled.

checking mod rewrite via command line

5. Asking Hosting Provider

The easiest way to check if mod_rewrite is enabled is to contact and ask the hosting provider about the module. Sites like Hostinger have it in their Knowledge Base as well.

mod rewrite pre installed in hostinger

Conclusion

There are multiple ways available for how to enable mod_rewrite in cPanel and If you don’t have access to certain files mentioned above, you can simply contact your hosting provider. It’s the best way to check if your mod_rewrite is enabled or not.

If the hosting provider has great support, you can always contact them and ask them to enable it. Most of the shared hosting providers will have already enabled it.

FAQ (Frequently Asked Questions)

What is mod_rewrite?

Mod_rewrite is an apache module used to manipulate URLs. It’s used to rewrite URLs, redirect users, or add other rules to a specific URL string.

Can you enable mod_security from cPanel?

Yes, you can enable it from the security section of your cPanel. The name is usually ModSecurity.

How useful was this article?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Comment