Halfpint
Halfpint

Reputation: 4079

.htaccess not working on my Ubuntu 14.04 Distribution

I have just configured my LAMP stack on my Ubuntu 14.04 distribution and want to set .htaccess up to serve a website.

I followed the tutorial https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file and configured a virtual host for my domain, however I am still unable to use the .htaccess file in my projects root, whenever I try to serve a page I get a 404 error.

The .conf file for my domain looks like:

 <VirtualHost *:80>
 ServerAdmin [email protected]
 ServerName alexsims.me
 ServerAlias www.alexsims.me
 DocumentRoot /var/www/alexsims.me

 <Directory />
    Options FollowSymLinks
    AllowOverride None
 </Directory>

 <Directory /var/www/alexsims.me>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
 </Directory>


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

I tried to change AllowOverride None to AllowOverride All but that caused an internal 500 error even after enabling mod_rewrite.

Regards, Alex.

EDIT: .htaccess contents

#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^alexsims.me [NC]
RewriteRule ^(.*)$ http://www.alexsims.me/$1 [L,R=301,NC]

#--- Rewrite PHP files clean URL
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)$ ?page=$1 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ ?page=$1&id=$2 [NC,L]

Upvotes: 2

Views: 6100

Answers (4)

Muhammad Shahzad
Muhammad Shahzad

Reputation: 9652

I have same issue with Ubuntu 15.10.

I solved this way.

First you need to enable rewrite module:

sudo a2enmod rewrite

sudo gedit /etc/apache2/apache2.conf

and replace

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

With:

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

And finally

sudo service apache2 reload

Actually what is difference between restart and reload !

restart= stop + start

reload = remain running + re-read configuration files.

We have changed configuration so we need to reload configuration.

It should help someone as I have wasted 4 hours :)

Upvotes: 3

Ken
Ken

Reputation: 78852

Try

Require all granted

in place of

Order allow,deny
allow from all

See the upgrade documentation for more info:

In 2.2, access control based on client hostname, IP address, and other characteristics of client requests was done using the directives Order, Allow, Deny, and Satisfy.

In 2.4, such access control is done in the same way as other authorization checks, using the new module mod_authz_host. The old access control idioms should be replaced by the new authentication mechanisms, although for compatibility with old configurations, the new module mod_access_compat is provided.

Upvotes: 2

Krzysztof Wołowski
Krzysztof Wołowski

Reputation: 455

You should check if the directives you use in .htaccess are enabled.

For example if you use RewriteEngine you should have apache module rewrite enabled:

cat /etc/apache2/mods-available/rewrite.load 
a2enmod rewrite
service apache2 restart

For ExpiresActive directive you should enable apache module expires:

cat /etc/apache2/mods-available/expires.load 
a2enmod expires
service apache2 restart

etc.

Upvotes: 1

Piskvor left the building
Piskvor left the building

Reputation: 92752

AllowOverride None

That's your problem, right there. The 500 error you're getting could mean that your .htaccess file is malformed - start

See http://httpd.apache.org/docs/current/mod/core.html#allowoverride

Upvotes: 1

Related Questions