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

标签 .htaccess apache2 virtualhost

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

我尝试了以下方法:

  • 已启用 mod_rewrite
  • 更改了 AllowOverrideAll但这会导致 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>
    

    在我的 .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
    

    我尝试过的一件事是将这些规则直接附加到 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,这应该是什么问题吗?文件?

    最佳答案

    看了我的 apache error.log我意识到我只需要启用 Apache actions模块:

    sudo a2enmod actions



    不再出现 500 个内部服务器错误!

    希望这可以帮助某人:)

    关于.htaccess - 如何使用 Apache VirtualHost 获取 .htaccess 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14419757/

    相关文章:

    ruby-on-rails - 为什么 Rails 应用程序显示/公共(public)索引列表而不是实际应用程序?

    .htaccess - 500 内部服务器错误 CakePHP

    regex - 替换搜索查询字符串使其成为 SEF

    apache2 - 为什么 Apache 不将我的 IP 地址重定向到服务器上的所需位置?

    单声道 IOMAP 区分大小写

    dart - 如何使用http_server程序包在Dart中提供多个虚拟Web应用程序?

    php - 我的 htaccess 文件无法加载 css

    .htaccess - GET-Request 中的斜杠 (/) 和我在 htaccess 中的 mod_rewrite 语句

    perl - 你推荐什么 Perl RESTful 框架?

    php - 如何在 Debian 上的 Apache 2.4 中为每个虚拟主机选择 PHP 版本 5 和 7?