禁止您无权访问此服务器上的/

时间:2014-02-04 11:56:23

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

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

这么简单的愿望。我试图在互联网上找到解决方案。互联网告诉我在htdocs root中添加一个 .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>

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

  

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

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

6 个答案:

答案 0 :(得分:163)

感谢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

Apache 2.4 中不推荐使用订单允许指令。

答案 1 :(得分:13)

工作方法{如果配置以外没有问题}

默认情况下,Appache从ipv4 不限制访问。 (普通外部IP)

可能限制的是httpd.conf&#39;中的配置。 (或者&#39; apache2.conf&#39;取决于您的apache配置)

解决方案:

全部替换:

<Directory />
     AllowOverride none
    Require all denied

</Directory>

<Directory />
     AllowOverride none
#    Require all denied

</Directory>

因此删除了对Apache

的所有限制

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

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

答案 2 :(得分:3)

解决方案很简单。

如果您尝试使用本地IP地址访问服务器,则会收到错误消息,例如禁止您无权访问/在此服务器上

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

搜索

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

替换 允许来自127.0.0.1

允许所有

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

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

答案 3 :(得分:2)

问题在于https.conf文件!

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

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

答案 4 :(得分:1)

在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

答案 5 :(得分:0)

这在Mac OS Mojave上对我有效:

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