Can't get apache rewrites to work

August 3, 2015 1.1k views
PHP Apache

Hi,

I've setup a droplet with Ubuntu LAMP on 14.04, enabled mod_rewrite using sudo a2enmod rewrite and confirmed this with phpinfo().

I've also setup a vhost with using the following config:

<VirtualHost *:80>
    ServerAdmin foo@foo.co.uk
    ServerName foo.com
    ServerAlias dev.foo.com
    DocumentRoot /var/www/dev_foo/public_html/application/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

My 000-default.conf file is this:

<VirtualHost *:80>

        ServerName localhost

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        <Directory />
          Options FollowSymLinks
          AllowOverride All
        </Directory>

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

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

But I can't get it to work, any tips?

Thanks

3 Answers

In order for directives in an .htaccess file to be used you need AllowOverride All set for the vhost responding to the request. You will want to copy over the relevant section from the default to your new vhost and restart apache:

        <Directory />
          Options FollowSymLinks
          AllowOverride All
        </Directory>
service apache2 restart

After that the .htaccess directives should work properly.

Thanks for the speedy response, sadly I've tried that and it doesn't work :(

If you're having problems configuring your server to enable mod_rewrite, you might want to try a software stack such as the one used by ServerPilot that enables mod_rewrite by default for your sites.

Have another answer? Share your knowledge.