.htaccess不工作在我的Ubuntu 14.04发行版

我刚刚在我的Ubuntu 14.04发行版上configuration了我的LAMP堆栈,并且想要设置.htaccess来为网站提供服务。

我跟着教程https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file并为我的域configuration了一个虚拟主机,但是我仍然无法使用.htaccess文件我的项目根,每当我尝试服务一个页面,我得到一个404 error

我的域的.conf文件如下所示:

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

我试图将AllowOverride None更改为AllowOverride All但即使在启用mod_rewrite之后也会导致内部500错误。

问候,亚历克斯。

编辑: .htaccess内容

 #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] 

尝试

 Require all granted 

代替

 Order allow,deny allow from all 

有关更多信息,请参阅升级文档 :

在2.2中,基于客户端主机名,IP地址和客户端请求的其他特征的访问控制是使用指令Order,Allow,Deny和Satisfy完成的。

在2.4中,这种访问控制与其他授权检查相同,使用新模块mod_authz_host。 旧的访问控制成语应该被新的认证机制所取代,尽管为了与旧的配置兼容,提供了新的模块mod_access_compat。

我有与Ubuntu 15.10相同的问题。

我解决了这个问题

首先你需要启用重写模块:

sudo a2enmod rewrite

sudo gedit /etc/apache2/apache2.conf

并更换

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

附:

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

最后

sudo service apache2 reload

其实restartreload什么区别!

restart= stop + start

reload = remain running + re-read configuration files.

我们改变了配置,所以我们需要重新加载配置。

它应该帮助一个人,因为我浪费了4个小时:)

 AllowOverride None 

那就是你的问题,就在那里。 您收到的500错误可能意味着您的.htaccess文件格式不正确 – 开始

请参阅http://httpd.apache.org/docs/current/mod/core.html#allowoverride

您应该检查您在.htaccess中使用的指令是否已启用。

例如,如果您使用RewriteEngine,则应该启用apache模块重写:

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

对于ExpiresActive指令,你应该启用apache模块失效:

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

等等