【问题标题】:.htaccess: RewriteEngine not allowed here.htaccess:此处不允许使用 RewriteEngine
【发布时间】:2023-03-04 02:58:02
【问题描述】:

我将 .htaccess 上传到服务器并收到 错误 500(内部服务器错误)

在错误日志中我有以下错误:

.../.htaccess:此处不允许使用 RewriteEngine

mod_rewrite.so 已启用。

那么,我需要改变吗

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>

/etc/httpd/conf/httpd.conf 文件中?

或者是别的什么? .htaccess 文件应该没问题,因为它在我的本地主机上运行良好。我只是不想搞砸任何事情。

这是我的 .htaccess 文件的一部分:

Options All -Indexes

Options +FollowSymLinks

RewriteEngine On

【问题讨论】:

  • 是的,这都是关于 AllowOverride 指令的。不需要AllowOverride All .. 但至少AllowOverride FileInfo。详情:httpd.apache.org/docs/current/mod/core.html#allowoverride
  • 错误日志显示的就是这些?
  • @linuxeasy 是的。路径和 .htaccess: RewriteEngine 不允许在这里。就是这样。
  • @lazyone,谢谢,我试试看。

标签: .htaccess mod-rewrite apache httpd.conf


【解决方案1】:

.htaccess 工作的最低配置:

AllowOverride FileInfo Options

允许所有配置也可以:

AllowOverride All

【讨论】:

  • AllowOverride All wroked 但 AllowOverride FileInfo Options 没有,wp-includes/.htaccess: deny not allowed here
  • @Jacek Kaniuk 如何在 1and1 中允许 htaccess
  • AllowOverride 控制可以在.htaccess 中使用的指令的类型。因此AllowOverride FileInfo Options 是否足够完全取决于您使用的指令。 FileInfo 是 mod_rewrite 所必需的,FileInfo Options 是问题中 .htaccess 文件所必需的。要在.htaccess 中使用Deny,您还需要包含Limit 指令类型。 @Sérgio 但大多数人只是坚持使用All 以“易于使用”。
  • 但是,与此答案的含义相反,您不应在 &lt;Directory /&gt; 容器中设置除 AllowOverride None 以外的任何内容(如问题中所述) - 它指的是 服务器根 - Apache docs 特别警告不要“出于安全和性能原因”这样做。相反,这应该为包含.htaccess 文件的特定目录设置,例如 DOCUMENT_ROOT,如@anubhava 的回答中所述。
【解决方案2】:

假设你的 DOCUMENT_ROOT 是 /home/foo/web 然后在你的 httpd.conf 文件中有这个配置:

<Directory "/home/foo/web">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

这应该可以解决您遇到的RewriteEngine is not allowed 错误。

【讨论】:

    【解决方案3】:

    只是一个想法,这发生在我身上,我已经浪费了很多时间试图解决它。

    如果你有d:/web/my-sites/some-site/这样的目录

    然后你将.htaccess 放在d:/web/my-sites/some-site/.htaccess(它应该在的地方)。

    如果您在此目录之前有任何 .htaccess 文件,Apache 会读取该文件并阻止整个路径的执行,从而产生内部服务器错误。

    IE:你有d:/web/my-sites/.htaccess

    【讨论】:

    • 我刚刚找到了解决办法,stackoverflow.com/questions/32084190/…
    • 这仍应取决于您设置AllowOverride(以及Apache 2.4+ 上的AllowOverrideList)的方式/位置。可能还有 Apache 版本,因为 AllowOverride 指令的默认值在 Apache 2.2 和 2.4 之间发生了变化。
    【解决方案4】:

    在 httpd 版本 2.4(2.4.3 和 2.4.4)中,查看 /etc/httpd/conf.d/wordpress.conf 有一个条目: ……

    改变: “允许覆盖选项” 到 “允许全部覆盖”

    在 wordpress.conf 中除了改变 httpd.conf 也一样。在更改生效之前重新启动 http 服务器。

    【讨论】:

      【解决方案5】:

      另外,请确保您正在编辑正确的配置文件。我在 /etc/apache2/users/USERNAME.conf 下创建了一个文件,但正在编辑 /etc/apache2/httpd.conf。

      删除 USERNAME.conf 文件有效。

      【讨论】:

        【解决方案6】:

        尝试将Mac上/etc/apache2/users/username.conf下的username.conf文件改成

        <Directory "/Users/akyoo/Sites/">
           AllowOverride All
           Options Indexes MultiViews FollowSymLinks
           Require all granted
        </Directory>
        

        我的.htaccess 文件如下所示

        #Allow from all
        Options +FollowSymLinks
        RewriteEngine on
        RewriteCond $1 !^(index\.php|resources|robots\.txt)
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L,QSA]
        

        这对我来说很好。 Solution for Ubuntu users

        【讨论】:

        • 只是添加,仅在您特别需要时启用MultiViews。如果您正在使用 mod_rewrite,如本例所示,那么您可能不使用 - 这可能会导致意外冲突。
        【解决方案7】:

        在检查来自 /var/log/apache2/error.log 的日志后,我从 Google Cloud 实例中收到了此类错误

        .htaccess: 此处不允许使用 RewriteEngine

        要摆脱上述错误和 500 内部服务器错误,请按照以下简单步骤操作

        sudo nano /etc/apache2/apache2.conf
        

        然后添加这些线的sn-ps

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

        进行更改后,请确保重新启动服务器:

        sudo service apache2 restart
        

        这对我摆脱了托管在 Google Cloud 实例上的 500 内部服务器错误

        【讨论】:

          【解决方案8】:

          您可以在 .htaccess 文件中使用类似的内容:

          RewriteEngine on
          RewriteCond $1 !^(index\.php|html|test)
          RewriteRule ^(.*)$ /index.php/$1 [L]
          

          这段代码只是意味着,任何不指向 index.php 或 html 或 test 的东西都应该指向 index.php!

          希望对您有所帮助!

          【讨论】:

          • 哦,我想我会用的,谢谢!但我认为这并不能解决 RewriteEngine 不被允许的问题。
          猜你喜欢
          • 2012-10-27
          • 2015-11-12
          • 2014-05-28
          • 1970-01-01
          • 1970-01-01
          • 2011-10-29
          • 2018-02-28
          • 1970-01-01
          相关资源
          最近更新 更多