如何使用Apache VirtualHost获取.htaccess文件

Jas*_*lsa 11 .htaccess apache2 virtualhost

我的问题是.htaccess我的本地服务器上的文件没有被读取.VirtualHost文件中的设置似乎始终优先.

我尝试过以下方法:

  • 启用 mod_rewrite
  • 更改AllowOverrideAll但这会导致a HTTP Error 500 Internal server error.我尝试了各种选项,但它总是导致500错误.

我在Ubuntu上使用VirtualHost文件,如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

在我的.htaccess文件中,/web/website我有以下规则(未被阅读):

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
Run Code Online (Sandbox Code Playgroud)

我尝试过的一件事就是将这些规则直接附加到VirtualHost文件中,但我希望我的.htaccess文件能够正常工作!这是一个如此大的问题吗?:(

编辑:所以我查看了我的apache error.log,它说Invalid command 'Action', perhaps misspelled or defined by a module not included in the server configuration我的.htaccess文件.似乎没有一个名为Action的模块,我可以启用它.有任何想法吗?

编辑2:我注意到我的httpd.conf文件是空白的.这是不是因为我使用VirtualHost文件?

Jas*_*lsa 6

看了我的apache后,error.log我意识到我必须启用Apache actions模块:

sudo a2enmod行动

并且不再有500个内部服务器错误!

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