Browse: Popteen Blog » Culture Channel»How to Enable mod_rewrite in Apache Server Tutorial Guide

How to Enable mod_rewrite in Apache Server Tutorial Guide

How to enable mod_rewrite in Apache server? Apache configuration could block mod rewrite? Rewrite and manipulate URLs which are sent to webserver. If you have shell access or SSH access to your linux dedicated sever, the easiest way is to check your configuration file.

The first in a series of mod_rewrite tutorials on tutorio websie. This tutorial is an introduction to mod_rewrite and you will also learn how to enable mod_rewite on your Apache server with this tutorial.

I’ve got fresh install of Apache 2.2 on my linux dedicated server, everything works fine, except mod rewrite. But now I need to enable mod_rewrite in Apache Server. All the rules I’m using are working on my hosting, so they should be ok, so my question is, is there any hidden thing in apache configuration, that could block mod rewrite?

Before you begin this, please make sure you make a backup copy of the original file in case you make a mistake, this way you can always go back to the original configuration – always backup before you begin doing something like this.)

Step One: Find the httpd.conf file (usually you will find it in a folder called conf, config or something along those lines. In Fedora you can find it at /etc/httpd/ directory.)

Step two: Inside the httpd.conf file find and uncomment the line LoadModule rewrite_module modules/ (remove the pound ‘#’ sign from in front of the line – the # sign is for comments, by removing the # sign, you are uncommenting the line)

Step three: Also find the line ClearModuleList is uncommented then find and make sure that the line AddModule mod_rewrite.c is not commented out. (I didnt find these in Fedora, yet my mod_rewrite works great)

Step four: After you have made the changes and saved them, restart your httpd (apache) server for the changes to take affect. The easiest way to do this is to go to the shell command and type: /etc/init.d/httpd restart (this works for Fedora, might be different for other distributions!) Done

Introduction to mod_rewrite and Apache Server

Mod_rewrite allows you to rewrite a webpage’s url on the fly, and you can rewrite the url to almost anything. It has a lot of uses everything from redirecting multiple WebPages to a new domain without actually changing the title, to making dynamic pages appear static.

However, it is somewhat complicated to learn, and if you make a mistake its also possible to really mess-up your server and create endless loops. Need less to say I don’t recommend messing around with this on you live site. The solution, if you want to mess around and experiment with it is, to run a test server on your own computer for test purposes.

How to Enable mod_rewrite in Apache Server Tutorial

Tutorial Sponsor: (tutorial continues below)

Do you need extensive computer training? A+ training that CBT Planet offers can help you obtain your IT certification. Computer experience and knowledge are essential in order to advance your business as well as your education. So get going on learning more about how to utilize the computer and it’s resources at CBT Planet My own server ?

Apache by default comes with the mod_rewrite module installed but not enabled. So if you have Apache installed on your home computer chances are that all you have to do is enable mod_rewrite (explained later in this tutorial).

If you don’t have Apache installed, you can install it yourself, or get one of the many Apache, php, mysql bundles and install it yourself fairly easily. Most (if not all) of these bundles use the default settings, and mod_rewrite is not enabled by default, so come back and read this tutorial once you are done installing apache web server.

If you want to learn how to check it mod_rewirte is enabled, check this post:  if you have shell access or SSH access to your sever, the easiest way is to check your configuration file. check this post to see how:


mod_rewrite is a module for Apache Web Server which allows you to rewrite and manipulate URLs which are sent to your webserver.

In this tutorial I will explain how to enable mod_rewrite with Apache 2.2* in a Debian Linux.

To enable the module, type this command:

a2enmod rewrite


root@server:~# a2enmod rewrite
Module rewrite installed; run /etc/init.d/apache2 force-reload to enable.
Now reload apache:

/etc/init.d/apache2 force-reload


root@server:~# /etc/init.d/apache2 force-reload
Forcing reload of web server (apache2)…httpd (1654)
All went fine, but is possible that you receive an error, for example, if you have some defined mod_rewrite rules setted in the apache.conf or httpd.conf you can get this error as output:

root@server:~# /etc/init.d/apache2 force-reload
Forcing reload of web server (apache2)… waiting Syntax error on line 123 of /etc/httpd/apache2.conf:
RewriteBase: only valid in per-directory config files

To fix this kind of error is pretty simple, you need only to remove the rule from apache2.conf, in my example I removed this code:

IfModule mod_rewrite.c
RewriteEngine On
RewriteBase /test/
RewriteCond %{REQUEST_SCRIPT} !-f
RewriteCond %{REQUEST_SCRIPT} !-d
RewriteRule . /test/index.php [L]

Now you need to put the above code in the correct place: inside a folder.

In my example code I need to modify URLs of all requests made under the folder /test/, so I will copy the code in an empty file named .htaccess and I will save the file under /test/.htaccess.

Now we need to set the option AllowOverride in our apache2.conf for the folder /test/ and I will use vi to edit the apache2 config file:

root@server:~# vi /etc/httpd/apache2.conf
Now I will add this code:

Directory /var/webhost/
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all

Note that I used the option AllowOverride to All.

To see if all is working good, just reload your apache:

/etc/init.d/apache2 reload

and test the changes in your browser.

Otherwise, follow these steps

Check to see if mod_rewrite is enabled

In addition, you can learn how to enable mod_rewrite in apache server at this post:

There are several ways to check if its working, I will try to show you the easiest way-

Create a .htaccess file (a text file named .htaccess) with the following code in it
Options +FollowSymLinksRewriteEngine On

Save the file to a subdirectory of your main site something like this


Now attempt to browse to the subdirectory (http://localhost/rewrite-testfolder/). One of two things could happen

– No errors Congrats mod_rewrite engine is now enabled.

– 500, Internal Server Error If you get this message then mod_rewrite was not installed/enabled on your computer.

If you get a 500 error, you can learn to how to enable mod_rewrite in apache by visiting this post:

If you did the above and still your mod_rewrite is not working read this:

How To Troubleshoot mod_rewrite in Apache Linux Server Guide

If you are hosted by a shared hosting company and dont have shell access, i suggest you contact your web hosting company. But most likely they will have some excuse for you and not change their apache configuration because they will be afraid that whatever changes they do in their server, it will affect other customers, so most likely they will not help you. Best thing to do is to host you own website. If you have cable or dsl, you can make your PC into an apache server very simple. In the future, I hope to write and share my knowlege to write a tutorial guide for building and configuring a web server for your domain website out of a simple Intel Personal Computer.

How to enable mod_rewrite in Ubuntu server?

I’m trying to find the right way/file to enable mod_rewrite. I know the typical place to do this is in httpd.conf, but of course Ubuntu has its own funky way of doing this with the mods-available and sites-available conf files.

What’s the official way to enable mod_rewrite on Ubuntu?

I assume you are talking about Apache2 directory structure for Ubuntu. This is the new and modular way all distributions will be laying out their Apache2 server config.

Mod_rewrite is compiled in by default. You can see it in the /etc/apache2/mods_available directory. If you feel like making doubly sure that it is loaded then simply put the following directive into httpd.conf:


LoadModule mod_rewrite /usr/lib/apache2/modules/mod_rewrite.soYou can verify what modules are loaded with: Code: sudo apache2ctl -lT Editing by Rose White

Ok Popteen Magazine Guys it's your turn to tell me what you think, ask a question or suggest a great tip. Don't forget the comments policy and I'm looking forward to reading what you have to say. It is your time, do cherish it and talk NOW!

Wow, No comments yet! Want to be the first one to talk?

Leave a Reply

Popteen Magazine, a High Fashion Style at