PHPDeveloper

Enabling Mod Rewrite on Ubuntu

by Jarrod posted 6 months 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 ?

Type Your Comment