【问题标题】:Forbidden You don't have permission to access / on this server [closed]禁止您无权访问此服务器上的 / [关闭]
【发布时间】:2014-02-28 09:13:12
【问题描述】:

我今天想做的就是将重定向规则写入子文件夹,例如: 您输入 URL:example.com 并被重定向到 example.com/subfolder

这么简单的愿望。我试图在互联网上找到解决方案。互联网告诉我在 htdocs 根目录中添加一个 .htaccess 文件:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ subfolder [L]

我做到了。但显然没有成功,他们没有告诉我必须取消注释 httpd.conf 中的模块:

LoadModule rewrite_module modules/mod_rewrite.so

所以我也这样做了。又没有成功。他们没有告诉我必须更改我的 httpd.conf 以便启用 .htaccess 文件:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

DocumentRoot "c:/Apache24/htdocs"
<Directory "c:/Apache24/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

再次没有成功,因为我在输入 URL 时收到此错误:

Forbidden 您无权访问此服务器上的 /。

现在我被困住了,在互联网上找不到更多解决方案。出于私人原因,我只是在我的 Windows 7 机器上运行 Apache 2.4。

【问题讨论】:

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


【解决方案1】:

感谢Error with .htaccess and mod_rewrite,找到了我的解决方案
对于 Apache 2.4 和所有 *.conf 文件(例如 httpd-vhosts.conf、http.conf、httpd-autoindex.conf ..etc)使用

Require all granted

而不是

Order allow,deny
Allow from all

OrderAllow 指令在 Apache 2.4 中已弃用。

【讨论】:

  • 天哪,刚从 centos 迁移过来,我很高兴看到这个。谢谢!
  • 该死的弃用! - Apache 错误消息会很好
  • 谢谢!这节省了我的一天!
  • 是的,完全同意@AndrewAtkinson。多年的 apache2,现在,相同的版本,不同的配置。
  • 很抱歉,我们应该把那行放在哪里?
【解决方案2】:

WORKING Method {如果除了配置没有问题}

默认情况下,Appache 不限制来自 ipv4 的访问。 (常用外网ip)

可能会限制“httpd.conf”(或“apache2.conf”,具体取决于您的 apache 配置)中的配置

解决方案:

全部替换:

<Directory />
     AllowOverride none
    Require all denied

</Directory>

<Directory />
     AllowOverride none
#    Require all denied

</Directory>

因此消除了对 Apache 的所有限制

C:/wamp/www/ 目录中将Require local 替换为Require all granted

<Directory "c:/wamp/www/">
    Options Indexes FollowSymLinks
    AllowOverride all
    Require all granted
#   Require local
</Directory>

【讨论】:

    【解决方案3】:

    解决方案很简单。

    如果您尝试使用您的本地 IP 地址访问服务器,并且收到类似 Forbidden You don't have permission to access / on this server

    的错误提示

    只需从(在我的情况下为 C:/wamp/bin/apache/apache2.2.21/conf/httpd.conf)打开您的 httpd.conf 文件

    搜索

    <Directory "D:/wamp/www/"> .... ..... </Directory>

    替换 允许来自 127.0.0.1

    所有人都允许

    保存更改并重新启动服务器。

    现在您可以使用您的 IP 地址访问您的服务器

    【讨论】:

      【解决方案4】:

      问题出在 https.conf 文件中!

      # Virtual hosts
      # Include conf/extra/httpd-vhosts.conf
      

      当 hash(#) 被删除或弄乱时会发生错误。这两行应该如上所示。

      【讨论】:

      • 请格式化您的答案。
      • 搞砸了什么?
      【解决方案5】:

      在 Apache/2.2.15 (Unix) 上找到了我的解决方案。

      感谢@QuantumHive 的回答:

      首先: 我都找到了

      Order allow,deny
      Deny from all
      

      而不是

      Order allow,deny
      
      Allow from all
      

      然后:

      我设置了

      #
      # Control access to UserDir directories.  The following is an example
      # for a site where these directories are restricted to read-only.
      #
      #<Directory /var/www/html>
      #    AllowOverride FileInfo AuthConfig Limit
      #    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
      #    <Limit GET POST OPTIONS>
      #        Order allow,deny
      #        Allow from all
      #    </Limit>
      #    <LimitExcept GET POST OPTIONS>
      #        Order deny,allow
      #        Deny from all
      #    </LimitExcept>
      #</Directory>
      

      把前面的“#”注释去掉

      #
      # Control access to UserDir directories.  The following is an example
      # for a site where these directories are restricted to read-only.
      #
      <Directory /var/www/html>
          AllowOverride FileInfo AuthConfig Limit
          Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
          <Limit GET POST OPTIONS>
              Order allow,deny
              Allow from all
          </Limit>
          <LimitExcept GET POST OPTIONS>
              Order deny,allow
              Deny from all
          </LimitExcept>
      </Directory>
      

      ps。我的 WebDir 是:/var/www/html

      【讨论】:

        【解决方案6】:

        这适用于我在 Mac OS Mojave 上:

        <Directory "/Users/{USERNAME}/Sites/project">
            Options +Indexes +FollowSymLinks +MultiViews
            AllowOverride All
            require all granted
        </Directory>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-09-11
          • 2014-06-07
          • 2018-08-06
          • 2012-06-08
          • 2013-05-15
          相关资源
          最近更新 更多