【发布时间】: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 文件。我删除了一个,现在可以了。谢谢