calebrown
By:
calebrown

Issues with Apache mod_rewrite and .htaccess

December 18, 2014 2.8k views

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.

1 comment
  • 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]
    
2 Answers

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

Have another answer? Share your knowledge.