How to Enable mod_rewrite
in Apache on Ubuntu
Works on Ubuntu 18.04, 20.04, 22.04, 24.04+
Compatible with Apache 2.4+
Step 1: Install Apache (If Not Already)
If Apache isn't installed yet:
Check Apache status:
Step 2: Enable mod_rewrite
Module
Run the following command:
Step 3: Configure Apache to Allow .htaccess
Overrides
Open your Apache config file. If you're using the default site:
Inside the <VirtualHost *:80>
block, add or edit this section:
This allows .htaccess
files in your /var/www/html
directory to work.
Step 4: Restart Apache
Apply the changes by restarting Apache:
Step 5: Create a Test .htaccess
File (Optional)
You can test if mod_rewrite
works by creating a .htaccess
file:
Paste the following:
Now, create a file:
Visit:http://localhost/hello
You should see the contents of test.html
.
Done!
mod_rewrite
is now enabled and working on your Apache server! You can now use .htaccess
files and pretty URLs in your web apps.