PHPDeveloper

Enabling Mod Rewrite on Ubuntu

by Jarrod posted 2 years ago
Enabling Mod Rewrite on Ubuntu

If you've already searched the Internet you'll like have quickly come across loads of posts about how to enable mod_rewrite on Ubuntu. Still doesn't work? I'll tell you why.

To begin, let's make sure you have actually enabled mod_rewrite. At your terminal prompt, enter the following:

$ sudo a2enmod rewrite

Easy. Did it work? if so great! If not, try these next couple of steps. Again in the terminal, open up the following file with:

$ sudo gedit /etc/apache2/sites-available/default

And now change the AllowOverride value to "All". I have included what the file should now look like for a default installation.

Restart Apache and you're done:

$ sudo service apache2 restart

Below is a sample file with the aforementioned changes.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride All                                 <- HERE
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All                                 <- HERE
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

Comments for Enabling Mod Rewrite on Ubuntu

  • Donald Duck
    Bram de Haan 2012-01-30 12:53:15

    Mr. Oberto, you just saved my day! Thank you so much.

  • Donald Duck
    Will 2012-03-28 04:01:25

    Thanks mate, worked very nicely.

  • Donald Duck
    videos 2012-04-13 09:58:08

    I get /bin/sh: $: command not found what to do ?

  • Donald Duck
    Chad de Lange 2012-05-22 14:18:17

    Thanx

  • Donald Duck
    Will 2012-06-11 08:03:29

    Thanks. "AllowOverride All" works.

  • Donald Duck
    Will 2012-07-09 19:40:15

    You are Mr. bad-ass! I've been to over 10 sites, but none of them helped me, till I read this.

  • Donald Duck
    Sistla V Abhishek 2012-08-05 15:01:48

    Thanks a lot Mr Jarrod .. This article did it finally for me :) :)

  • Donald Duck
    Will 2012-08-17 09:37:25

    Thanks! While loads of others didn't , your post really helped~!

  • Donald Duck
    John J. Camilleri 2012-11-05 01:48:09

    Everything was working fine until I upgraded Ubuntu, then suddenly for no reason my rewrite rules stopped working! I guess some Apache config file must have been overwritten; thanks for this, it was just what I needed!

  • Donald Duck
    Em 2012-12-07 18:32:53

    This post may be more than a year old but you just helped me solve a 2 1/2 yr old problem. Thanks for the tut it was spot on.

  • Donald Duck
    Dennis Johansen 2012-12-12 12:58:57

    Worked like a charm, thanks!

  • Donald Duck
    Yuugian 2012-12-20 06:03:37

    Worked for me also! I am saving this link in so many places. Thanks

  • Donald Duck
    Venerable Nandiya 2013-02-26 18:11:43

    These instructions worked perfectly! Exactly what we needed to end the frustration with getting mod_rewrite to work.

  • Donald Duck
    Stan 2013-03-27 06:25:43

    Great!!!!!!! It works! Fantastic! Thank you!

  • Donald Duck
    bright monkey 2013-05-06 08:08:49

    Thanks a lot! That helps :-)

  • Donald Duck
    Chase 2013-05-07 18:27:39

    Worked perfectly Thanks!

  • Donald Duck
    salim 2013-05-09 02:34:47

    This saved my day.

  • Donald Duck
    Dedicated Server 2013-05-25 13:49:53

    Thanks! Server works great!

  • Donald Duck
    Will 2013-06-25 03:07:54

    Thank you, this solved a problem I was suffering with Worpess' permalinks.

  • Donald Duck
    Will 2013-06-26 03:33:30

    God bless you! I wish I had located your site yesterday when I started facing the problem. Now it is fixed.

  • Donald Duck
    Nibin 2013-06-28 06:29:46

    You saved my whole day. Great work posting the information !

  • Donald Duck
    Will 2013-06-29 02:35:50

    Thank you! This helped with my wordpress migration, but I had to leave only these entries because apache wouldnt start otherwise: ServerAdmin webmaster@localhost DocumentRoot /var/www Options FollowSymLinks AllowOverride All <- HERE Options Indexes FollowSymLinks MultiViews AllowOverride All <- HERE Order allow,deny allow from all

  • Donald Duck
    Martien van Dijk 2013-07-16 11:37:02

    Hi, Thanks for the solution!

  • Donald Duck
    Will 2013-07-23 09:40:12

    Hey man... thanks for this article. As many have said... "you saved my day"

  • Donald Duck
    john 2013-08-01 06:11:45

    You saved my day bro!!!! Thank you!!!!!!

  • Donald Duck
    Will 2013-10-11 12:28:32

    'sudo a2enmod rewrite' and now im happy ;)

  • Donald Duck
    tin cong nghe 2013-11-14 10:58:00

    Thanks! Server works great!

  • Donald Duck
    Saman 2013-11-27 15:09:09

    Thank you so much for this helpful article.

  • Donald Duck
    Will 2013-11-29 05:40:43

    Very helpful, thx a lot :)

  • Donald Duck
    Maarten 2014-01-03 15:08:42

    Thanks!

  • Donald Duck
    Jacob 2014-01-12 10:13:18

    Hi, What about for the new 13.10 newer apache configuration: 000-default.conf this file looks completely different?

  • Donald Duck
    Jacob 2014-01-12 10:20:23

    Hi, What about for the new 13.10 newer apache configuration: 000-default.conf this file looks completely different?

  • Donald Duck
    Greg 2014-01-29 15:38:40

    Spot on. Have been battling with the apache configs for ages and found the rewrite modules was not on, a2enmod rewrite sorted it. Cheers

  • Donald Duck
    Jeffrin Jose 2014-03-06 10:43:08

    thanks it has helped me. is there any security issue in writing AllowOverride All

  • Donald Duck
    Appreciated! 2014-05-24 23:20:04

    Exceptional explanation with no BS, thank you!

  • Donald Duck
    Will 2014-05-25 15:33:36

    Straight-forward solution. Great!

  • Donald Duck
    Will 2014-06-12 21:21:52

    Thanks... work for me i edit AllowOverride none to AllowOverride All

  • Donald Duck
    Avi 2014-06-13 05:35:02

    Thanks, this stumped me for about an hour...

  • Donald Duck
    Will 2014-07-04 04:34:49

    thanks

  • Donald Duck
    Jason Estibeiro 2014-08-23 08:22:32

    Thanks dude! This really helped me!

  • Donald Duck
    Will 2014-09-06 13:20:07

    Thanks a lot !! = )

Type Your Comment