Question

Can't get apache rewrites to work

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


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.

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

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.