Report this

What is the reason for this report?

Issues with Apache mod_rewrite and .htaccess

Posted on December 18, 2014

Hey, I’m configuring my LAMP droplet (Ubuntu 14.04) to use a simple rewrite rule in the .htaccess file and it’s simply 404-ing every time. My conf file does indeed include the “AllowOverride All” rule (see entire file below) and the .htaccess file in my web directory includes these rules:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^([A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9])$ /index.php?i=$1 [L]
RewriteRule ^([A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9])/$ /index.php?i=$1 [L]

Conf File contents:

 <VirtualHost *:80>
    ServerAdmin caleb@scurrylabs.com
    ServerName sqworl.com
    ServerAlias www.sqworl.com
    DocumentRoot /var/www/sqworl.com/public_html

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

	<Directory "/var/www/sqworl.com/public_html">
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>

Any help at all would be much, much appreciated.



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!

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.

This question was answered by @sierracircle:

some things to check:

have you enabled mod rewrite?

sudo a2enmod rewrite

what is the name of your config file? does it match your domain name? are you using the default?

do you have any other rules in your .htaccess that you can check to verify that indeed your htaccess is working?

here is one you can try…this just makes it so when you type in www.yourdomain.com it should immediately go to http://yourdomain.com

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

View the original comment

I know this is old but for I had a similar problem and this was the fix that finally worked for me.

Go to /etc/apache2/apache2.conf file above and look for

<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>

Change “AllowOverride” from None to All

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.