.htaccess not working on my Ubuntu 14.04 Distribution

走远了吗. 提交于 2020-01-01 07:06:50

问题


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 alexmk92@live.co.uk
 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]

回答1:


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.




回答2:


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 :)




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/24675882/htaccess-not-working-on-my-ubuntu-14-04-distribution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!