Web Development

Setting up mod_rewrite in Ubuntu 7.10 Gutsy Gibon

Mod_rewrite is a very important library to enable search engine friendly URLs in apache web server. Almost every framework takes advantage of this mod to make user experience more colorful while browsing a page. If you are not sure what is a search engine friendly URL, have a look at the following examples

1. http://your_domain/yourpage.php?param1=list&param2=12
2. http://youor_domain/list/12

In the examples above, second one is more readable than the first one. In fact search engines don’t index pages from a dynamic URL(i.e first example) which ultimately lowers your page rank. Thats why search engine friendly URLs are very important to increase your ranking in search engines.

For web application developers, here is a “how to” to enable mod_rewrite in ubuntu 7.10 (I assume you have apache2 installed in your machine, :D)

Step 1:
sudo cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/

This will copy the available mod_rewrite loader to the appropriate directory. Apache will load all mods by reading these loader present in the “mods-enabled” directory.

Step 2:
If you have one virtual hosting (that means your localhost actually points to /var/www) then change the file “/etc/apache2/sites-enabled/000-default” and replace the following line

AllowOverride None

with

AllowOverride all

Step 3:
Restart your apache server using the following command
sudo /etc/init.d/apache2 restart

Now you need to check out if the mod_rewrite is working properly. Place the following code in a file named “.htaccess” in your localhost (/var/www) and point your browser to “http://localhost”. If you don’t see any 500 internal error, consider its working :)

RewriteEngine On

Easy, huh?

About the author

Written by .

If you found this post useful you may also want to check these out:

  1. Setting Up Apache, PHP & MySQL On Windows
  2. How to Install Apache 2 on Linux
  3. SEO Review Roundup
  4. Search Engine Spider-Friendly JavaScript Content
  5. CSS – Maximum benefits
  6. How to Install PHP 5 on Linux
  • TheAnomaly

    FWIW, this saved me like you can’t believe. I just spent the past two hours trying to figure this out–digging through all kinds of complicated junk, and FINALLY, I got here. Your commands worked perfectly, and I’m a happy man.

    Thank you very much.

  • jacinto

    thank you. that helped me a lot! Also works with 8.04.

  • http://www.slz.lt Saulius

    Thanks, this info was very usefull for me :)

  • bahodir

    Thank you man!
    Works great with 8.10 too.
    Stumbled. Thumbs UP.

  • Mohammad

    Thank You man, thank you. It was hours that i was engaging without coming to any result