如何获得.htaccess文件与Apache虚拟主机工作 [英] How to get .htaccess files working with Apache VirtualHost

查看:200
本文介绍了如何获得.htaccess文件与Apache虚拟主机工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,我的本地服务器上我的的.htaccess 文件不被读取。在虚拟主机文件中的设置似乎始终以precedence。

My problem is that my .htaccess file on my local server is not being read. The settings in the VirtualHost file seem to always take precedence.

我已经试过如下:

  • 已启用的mod_rewrite
  • 改变的的AllowOverride 所有但是这会导致 HTTP错误500内部服务器错误。我已经尝试过各种选择,但它总是会导致一个500错误。
  • Enabled mod_rewrite
  • Changed the AllowOverride to All but this causes a HTTP Error 500 Internal server error. I have tried it with various options but it always causes a 500 error.

我使用它看起来像下面的Ubuntu的一个虚拟主机文件:

I am using a VirtualHost file on Ubuntu which looks like the following:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /web/website
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /web/website>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>
</VirtualHost>

/网页/网站

在我的的.htaccess 文件我有以下规则(不被读取的):

In my .htaccess file under /web/website I have the following rules (which are not being read):

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{HTTP_USER_AGENT} ^facebookexternalhit
RewriteRule ^(.*)$ ogtags.php?$1 [L,QSA]
ErrorDocument 404 /404
ErrorDocument 401 /401

有一件事情我想这没有工作直接附加这些规则到虚拟主机的文件,但我想我的的.htaccess 文件中工作!那是这么大的问? :(

One thing I tried which did work was appending these rules directly into the VirtualHost file, but I would like my .htaccess file to work! Is that such a big ask? :(

编辑:所以,我看着在我的Apache error.log中和它说无效的命令'动作',也许通过不包括在服务器配置指的是我的的.htaccess 文件模块拼写错误或定义。似乎没有成为一个被称为动作模块,我可以启用。任何想法?

So I looked in my apache error.log and it says Invalid command 'Action', perhaps misspelled or defined by a module not included in the server configuration referring to my .htaccess file. There doesn't seem to be a module called Action which I can enable. Any ideas?

编辑2:我发现我的的httpd.conf 文件是空白。如若这件事情,因为我使用虚拟主机文件?

Edit 2: I noticed that my httpd.conf file is blank. Should this matter since I am using VirtualHost files?

推荐答案

在看着我的Apache error.log中我意识到我必须让阿帕奇动作模块:

After looking at my apache error.log I realised I just had to enable the Apache actions module:

须藤a2enmod行动

sudo a2enmod actions

和没有更多的500内部服务器错误!

And no more 500 Internal Server Errors!

希望这有助于有人下了线:)

Hope this helps somebody down the line :)

这篇关于如何获得.htaccess文件与Apache虚拟主机工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆