Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Web Servers»Apache»How to Enable Apache mod_rewrite Module in Ubuntu & Debian

    How to Enable Apache mod_rewrite Module in Ubuntu & Debian

    By RahulMay 16, 20152 Mins ReadUpdated:December 30, 2021

    The Apache mod_rewrite module is a rewriting engine based on defined rules. The Apache rewrite engine maps a URL to a directory path as well as to other URLs. In this tutorial, you will learn, how to enable the Apache mod_rewrite module and configure VirtualHost to use .htaccess files available under the document root.

    Advertisement

    Sometimes you faced issues the Apache server is not reading your .htaccess or Apache is not rewriting URLs while we are using correct rewrite rules in configuration files. This happens due to the Apache rewrite module is not being enabled. When we installed a fresh Apache server mod_rewrite is not enabled by default on your server, So to use rewrite configurations you need to manually enable the mode_rewrite module on your system.

    Enable Apache2 mod_rewrite Module

    We use a2enmod command to enable any modules in Apache2 web server. So use following command to enable mod_rewrite module in your Apache setup.

    sudo a2enmod rewrite
    

    Enable .htaccess for VirtualHost

    After enabling the Apache rewrite module, now you need to add “AllowOverride All” in your VirtualHost configuration file.

    1
    2
    3
    4
    5
    6
    7
    8
    <VirtualHost *:80>
        ServerName  www.example.com
        DocumentRoot /var/www/html
     
        <Directory /var/www/html>
            AllowOverride All
        </Directory>
    </VirtualHost>

    This setting can also be enabled globally by editing the Apache main configuration file.

    1
    2
    3
    4
    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
    </Directory>

    Restart Apache2

    After enabling the mod_rewrite module in Apache you also need to reload the Apache2 server to reload all configurations to the running environment.

    sudo systemctl restart apache2
    

    Apache Linux Mint mint Modules rewrite Ubuntu
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    CodeIgniter Remove index.php Using .htaccess

    How to Generate Random Passwords in Python

    How to Generate Random Password in Python

    Configuring the Nginx Reverse Proxy in Front of Apache

    View 2 Comments

    2 Comments

    1. MrSatoV on August 9, 2020 2:17 pm

      “…in your VirtualHost configuration file.”
      “…by editing the Apache main configuration file.”
      Would you mind sharing the location of these?

      Reply
      • Kris on October 31, 2020 11:12 pm

        /etc/apache2/apache2.conf is the main configuration file
        the VirtualHost files are in /etc/apache2/sites-enabled

        Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Error: EACCES: permission denied, scandir (Resolved)
    • How To Install Python 3.11 on Ubuntu 22.04 / 20.04
    • How to Install Python 3.11 on Amazon Linux 2
    • An Introduction to the “./configure” Command: Compiling Source Code in Linux
    • How to Install PHP 8.x on Pop!_OS
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.