在wamp中使用.htaccess时获取403 Forbidden代码

时间:2015-10-25 10:08:22

标签: apache .htaccess wamp

我尝试使用.htaccess文件(使用WAMP和Windows 10)来使用我的API。我得到了

  

403 Forbidden

错误。

我的.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文件夹

1 个答案:

答案 0 :(得分:0)

  

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

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

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

从那以后我猜想是你的API正在生成403?

你的.htaccess文件中的指令看起来好像是这样的:localhost/work/api/campaigns