171

I just installed the LAMP stack on my Ubuntu system.

The redirection is not working for me. I don't know how to fix it. Can anyone help me?

5
  • 3
    IMHO this question is not Ubuntu specific and should be migrated to Server Fault.
    – Paolo
    Jun 12, 2011 at 14:35
  • 2
    The OP installed Lamp on UBUNTU. How much more Ubuntu specific do you want?
    – wojox
    Jun 12, 2011 at 15:36
  • 1
    @wojov: I don't know about this case, but that argument doesn't work. "How can I use this application (on Ubuntu)?" are mostly off-topic.
    – user13032
    Jun 12, 2011 at 17:14
  • 23
    This is not a "How can I use application", but a "how to enable a specific feature in Ubuntu". Apache under Ubuntu uses a different configuration layout in which each module and virtual host is a file in /etc/apache2 and which can be enabled using a2* programs.
    – Lekensteyn
    Jun 12, 2011 at 18:58
  • You should describe what you have done to narrow down the problem, it
    – ericn
    Jul 6, 2015 at 15:40

2 Answers 2

247

To enable it the rewrite module, run "apache2 enable module rewrite":

sudo a2enmod rewrite

You need to restart the webserver to apply the changes:

sudo service apache2 restart

If you plan on using mod_rewrite in .htaccess files, you also need to enable the use of .htaccess files by changing AllowOverride None to AllowOverride FileInfo. For the default website, edit /etc/apache2/sites-available/default:

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            # changed from None to FileInfo
            AllowOverride FileInfo
            Order allow,deny
            allow from all
    </Directory>

After such a change, you need to restart Apache again.

5
  • 18
    I had more success with AllowOverride All Sep 26, 2013 at 9:42
  • Thanks! sudo a2enmod rewrite and FileInfo fixed it for me!
    – d-_-b
    Feb 23, 2014 at 21:08
  • 23
    For me that file was /etc/apache2/apache2.conf where I found that config entry
    – doc_id
    Mar 25, 2014 at 14:37
  • Yes make the two changes fixed the problem.
    – Adelin
    Dec 28, 2015 at 10:58
  • It is not working for me. I posted a question here askubuntu.com/questions/809619/failing-to-rewrite-url Aug 8, 2016 at 12:52
51

I dare to add a special answer (as a followup to the great answer above) regarding ubuntu 14.04 and .htaccess :

In 14.04, the name of the default configuration file is changed to 000-default.conf :

sudo gedit /etc/apache2/sites-available/000-default.conf

add the following to the end of the file :

<Directory "/var/www/html">
    AllowOverride All
</Directory>

For some reason, in Ubuntu 14.04 and apache2 the root is set to /www/html. If you want to change the webserver root back to good old /www, open 000-default.conf and change

DocumentRoot /var/www/html/

to

DocumentRoot /var/www/

and then off course it should be

<Directory "/var/www">
    AllowOverride All
</Directory>
2
  • 1
    Thanx for info! This/new way we can use www as folder where we put all websites, and html is by default "website" for localhost. May be important if you are playing with opening ports to world - that this way your localhost cannot see folders of other projects. Nov 27, 2015 at 17:34
  • 1
    It is not working for me. I am using Ubuntu 14.04.4 LTS Aug 22, 2016 at 11:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .