huanix

chown -R huanix /

huanix header image 2

mod_rewrite for Apache2 in Ubuntu Feisty Fawn 7.04

April 18th, 2007 · 22 Comments

mod_rewrite is a module for the Apache webserver that allows apache to dynamically change the url of a site using php (or other scripting languages). It seems like a difficult/confusing task at first, but it actually only takes 2 steps in Ubuntu . I’m using Feisty Fawn, 7.04, but this should work well for Edgy and Dapper without any issues. Any code snippets should be typed into a terminal. “sudo” commands require a password, that’s a given.

  1. Enable mod_rewrite in Apache
    sudo a2enmod rewrite
  2. Edit the configuration file.
    1. sudo gedit  /etc/apache2/sites-available/default
    2. line 12 says “AllowOverride none” ;
    3. change it to “AllowOverride all”
    4. save and close
  3. Okay… one last step — you have to manually restart Apache (or restart your computer!)
  4. sudo apache2 -k restart

All done! now Apache and php can create URL’s on the fly – pretty neato!

Tags: Apache2 · HTML formatting · Server · php · ubuntu

22 responses so far ↓

  • 1 Lloyd Budd // Jun 19, 2007 at 3:37 pm

    Thank you, this solved my problem.

  • 2 Midlain // Jul 15, 2007 at 8:46 am

    Very helpful. Thanks & cheers! :)

  • 3 Del // Jul 19, 2007 at 9:58 am

    Thank you. I have been looking for this solution for a while now. Thank you.

  • 4 laizer // Aug 22, 2007 at 5:05 am

    Awesome. Huge help.

  • 5 Jim // Sep 2, 2007 at 3:46 pm

    I have been beating my head against a wall figuring out why PHP5 wasn’t working, this fixed it in 5 minutes. Thanks for the help.

  • 6 MaĆ«l // Sep 28, 2007 at 11:54 pm

    Wow. Thanks a lot.
    All the help I could gather up to now was only dealing with apache2.conf ;
    editing ‘default’ really was the point. :)
    You just saved my night ! ;)

  • 7 adler medrado // Oct 12, 2007 at 5:40 pm

    Thank you. It was very useful for me.

    regards,

  • 8 chris // Dec 10, 2007 at 8:23 pm

    This was very helpful. Thanks.

  • 9 Student Affairs - Austin » mod_rewrite for Apache2 in Ubuntu Feisty Fawn 7.04 // Jan 10, 2008 at 8:34 am

    [...] This article is originally from Huanix tutorial site [...]

  • 10 Brian Hart // Mar 18, 2008 at 1:04 pm

    Very helpful, thanks for the succinct tip.

  • 11 colombiano // May 25, 2008 at 2:57 pm

    gracias, it worked for me

  • 12 sagittariuspl // Jun 20, 2008 at 8:36 am

    if you want restart apache use sudo /etc/init.d/apache2 restart

  • 13 Monroe // Jul 25, 2008 at 4:22 pm

    Works perfect on Ubuntu hardy Heron, but restarting using “sudo /etc/init.d/apache2 restart”

  • 14 jose // Sep 16, 2008 at 3:57 pm

    hi, i have this message, after restart apache2:
    ~$ sudo apache2 -k restart
    apache2: bad user name ${APACHE_RUN_USER}

  • 15 mnich // Sep 30, 2008 at 3:13 am

    done :D thanks

  • 16 armand // Oct 12, 2008 at 3:01 am

    YUSS

    thanks!

  • 17 Verych // Nov 25, 2008 at 8:30 am

    Jose… try this:
    sudo apache2ctl restart

    -
    very helpfull post, thanks TC!

  • 18 Kolby Heacock // Dec 14, 2008 at 12:45 am

    thank you tons!

  • 19 pinochet // Jan 3, 2009 at 1:56 pm

    Hi. On my server rule: RewriteRule ^(.+)$ index.php?r=$1 give me : The requested URL /home/pinochet/public_html/sklep/index.php was not found on this server. But this file exist :(

  • 20 Lavanya // Feb 28, 2009 at 12:14 am

    Very simple and straight to the point.Was exactly what I was looking for!Thanks

  • 21 Ratius // Apr 11, 2009 at 10:17 pm

    Thanks a lot, it solved exactly what I was looking for

  • 22 Lounis // May 26, 2009 at 6:52 am

    Thank you, I solved my problem exactly following steps your wrote
    An other time, thank you

Leave a Comment

Wiki: Sync in Linux