【问题标题】:Getting 403 Forbidden code when using .htaccess in wamp在 wamp 中使用 .htaccess 时获取 403 禁止代码
【发布时间】:2015-10-25 10:08:21
【问题描述】:

我正在尝试通过使用.htaccess 文件(使用 WAMP 和 Windows 10)来使用我的 API。我得到一个

403 禁止

错误。

我的.htaccess 文件位于c/wamp/www/work

    Options -Indexes

#Set the response headers
<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Methods "*"
</IfModule>

<IfModule mod_rewrite.c>

    #Enable the Rewrite Engine
    RewriteEngine On

    #Rewrite the base to /work
    RewriteBase /work

    #If the request if not for the receiver - redirect to the api server
    RewriteRule ^api/(.*)$ api\index.php?request=$1 [QSA,NC,L]

</IfModule>

在我的httpd.conf 文件中,我添加了以下内容

<Directory "c:/wamp/www/">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    #
    # Controls who can get stuff from this server.
    #

#   onlineoffline tag - don't remove
    Require all granted
</Directory>

但我仍然收到403 Forbidden 错误。我知道.htaccess 文件有效。

也在我的http://localhost/work/ 我可以看到所有文件夹除了 api 文件夹

【问题讨论】:

  • 服务器配置中的双星号是什么意思? (尝试造型?)
  • 您在RewriteRule 替换中有一个反斜杠,而不是(正向)斜杠 - 尽管这应该导致 404,而不是 403。请您提供请求 URL 的示例。
  • 我修复了这个问题,但我仍然得到 403。请求的 URL 示例:http://localhost/work/api/index.php?campaigns,我得到:You don't have permission to access /work/api/index.php on this server.
  • 您可以访问任何文件吗?如果您删除 .htaccess,您可以访问任何内容吗?
  • 问题已解决。我有 2 个 htacess 文件。我删除了一个,现在可以了。谢谢

标签: apache .htaccess wamp


【解决方案1】:

请求的 URL 示例:localhost/work/api/index.php?campaigns

鉴于 .htaccess 文件中的指令,该 URL 没有多大意义,因为它会被重写为:

/work/api/index.php?request=index.php&campaigns

据此我猜是您的 API 生成了 403?

您的 .htaccess 文件中的指令看起来像是在期待:localhost/work/api/campaigns?

【讨论】:

  • 我无法访问 api 文件夹中的文件。请求是确定的。即使我只是尝试联系http://localhost/work/api/,我也会收到 403 Forbidden
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-11
  • 2015-04-18
  • 2012-07-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多