How Do I Enable Rewrite Module on My Web Server?


Angela Bailey

The Rewrite module is an essential component of your web server that allows you to manipulate URLs and redirect requests. By enabling the Rewrite module, you gain control over the URL structure of your website, making it easier to improve SEO and create user-friendly URLs. In this tutorial, we will walk you through the steps to enable the Rewrite module on your web server.

Step 1: Accessing the Server Configuration

Before you can enable the Rewrite module, you need to access your server configuration file. The location of this file varies depending on the web server software you are using.


If you are using Apache as your web server, the configuration file is typically named httpd.conf or apache2.conf. It is usually located in the /etc/apache2/ or /etc/httpd/ directory.


If Nginx is your web server, open the configuration file named nginx. This file is commonly found in the /etc/nginx/ directory.

Step 2: Enabling the Rewrite Module

In Apache:

To enable the Rewrite module in Apache, follow these steps:

  1. Navigate to your Apache configuration directory using a text editor:
    • $ sudo nano /etc/apache2/apache2.conf
  2. Locate the line that starts with “#LoadModule rewrite_module modules/“. Remove the leading “#” symbol to uncomment this line and enable the module.
  3. Save the changes and exit the text editor.
  4. Restart Apache for the changes to take effect:
    • $ sudo service apache2 restart

In Nginx:

To enable the Rewrite module in Nginx, follow these steps:

  1. Open your Nginx configuration file in a text editor:
    • $ sudo nano /etc/nginx/nginx.conf
  2. Inside the “http” block, add the following line to enable the Rewrite module:
    • include /etc/nginx/conf.d/*.conf;
  3. Save the changes and exit the text editor.
  4. Restart Nginx to apply the changes:
    • $ sudo service nginx restart

Step 3: Verifying Module Activation

To verify if the Rewrite module is successfully enabled, you can create a simple test. Create a new file named “.htaccess” in your website’s root directory and add the following content:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^(.*)$ index.php/$1 [L]

If you’re using Nginx, create a new file named “nginx.conf” inside the “/etc/nginx/conf.d/” directory and add this content:

location / {
  rewrite ^/(.*)$ /index.php/$1 last;

Save the changes and restart your web server.

If you encounter any issues, make sure to check your server’s error logs for more information.


Congratulations! You have successfully enabled the Rewrite module on your web server.

With this powerful tool at your disposal, you can now manipulate URLs and redirect requests to enhance the functionality and user experience of your website. Remember to always test and validate your rewrite rules to ensure they work as intended.