如何使用 Apache VirtualHost 获取 .htaccess 文件 [英] How to get .htaccess files working with Apache VirtualHost
问题描述
我的问题是我的本地服务器上的 .htaccess
文件没有被读取.VirtualHost
文件中的设置似乎总是优先.
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
更改为All
,但这会导致HTTP 错误 500 内部服务器错误
.我尝试了各种选项,但它总是导致 500 错误.
- Enabled
mod_rewrite
- Changed the
AllowOverride
toAll
but this causes aHTTP Error 500 Internal server error
. I have tried it with various options but it always causes a 500 error.
我在 Ubuntu 上使用 VirtualHost 文件,如下所示:
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>
在我的 /web/website
下的 .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
我尝试过的一件事是将这些规则直接附加到 VirtualHost 文件中,但我希望我的 .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
并显示 Invalid command 'Action',可能拼写错误或由未包含在其中的模块定义服务器配置
指的是我的 .htaccess
文件.似乎没有我可以启用的名为 Action 的模块.有什么想法吗?
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
文件是空白的.由于我使用的是 VirtualHost
文件,这是否重要?
Edit 2: I noticed that my httpd.conf
file is blank. Should this matter since I am using VirtualHost
files?
推荐答案
在查看我的 apache error.log
后,我意识到我只需要启用 Apache actions
模块:
After looking at my apache error.log
I realised I just had to enable the Apache actions
module:
sudo a2enmod 操作
sudo a2enmod actions
不再有 500 个内部服务器错误!
And no more 500 Internal Server Errors!
希望这对某人有所帮助:)
Hope this helps somebody down the line :)
这篇关于如何使用 Apache VirtualHost 获取 .htaccess 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!