我在运行本地服务器的OSX机器上开发时创建了一个.htaccess文件来控制对REST API的访问。但是,我需要部署的实际主机也是运行XAMPP的Windows机器。我使用相同的.htaccess文件并将其从开发服务器移动到实时服务器,它似乎不再正常运行。
这是.htaccess文件内容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule api/v1/(.*)$ api/v1/api.php?request=$1 [QSA,NC,L]
</IfModule>
.htaccess文件与api.php文件位于同一目录中,该文件是单个目录。因此,当我访问从OSX计算机托管的此页面时,它位于:
<IP Address>/RESTDevelopement/api.php
(机器上的实际文件夹路径为:.../Documents/RESTDevelopment/api.php
)
当我转到网址时:<IP Address>/RESTDevelopement/api/v1/query/
它会通过向<IP Address>/RESTDevelopement/api.php?request=query/
发送请求来回复
这很好用,我已经使用了几个星期没有问题。
然而,Windows机器却不是这样......
在我的Windows机器上运行XAMPP服务器并将项目存储在 htdocs 文件夹中。实际位置是:
G:\xampp\htdocs\RESTDevelopment\api.php
我以与OSX相同的方式访问它:
<IP Address>/RESTDevelopement/api.php
但是,当我转到同一页面使用api <IP Address>/RESTDevelopement/api/v1/query/
时,它会给我一个内部服务器错误。
日志文件表明它处于重定向循环中。我尝试按照循环使用,但它对我没有多大意义:
[Tue Jan 05 11:41:15.925963 2016] [rewrite:trace3] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c81030/initial] [perdir G:/xampp/htdocs/RESTDevelopment/] add path info postfix: G:/xampp/htdocs/RESTDevelopment/api -> G:/xampp/htdocs/RESTDevelopment/api/v1/query/
[Tue Jan 05 11:41:15.925963 2016] [rewrite:trace3] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c81030/initial] [perdir G:/xampp/htdocs/RESTDevelopment/] strip per-dir prefix: G:/xampp/htdocs/RESTDevelopment/api/v1/query/ -> api/v1/query/
[Tue Jan 05 11:41:15.925963 2016] [rewrite:trace3] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c81030/initial] [perdir G:/xampp/htdocs/RESTDevelopment/] applying pattern 'api/v1/(.*)$' to uri 'api/v1/query/'
[Tue Jan 05 11:41:15.925963 2016] [rewrite:trace2] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c81030/initial] [perdir G:/xampp/htdocs/RESTDevelopment/] rewrite 'api/v1/query/' -> 'api/v1/api.php?request=query/'
[Tue Jan 05 11:41:15.925963 2016] [rewrite:trace3] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c81030/initial] split uri=api/v1/api.php?request=query/ -> uri=api/v1/api.php, args=request=query/
[Tue Jan 05 11:41:15.925963 2016] [rewrite:trace3] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c81030/initial] [perdir G:/xampp/htdocs/RESTDevelopment/] add per-dir prefix: api/v1/api.php -> G:/xampp/htdocs/RESTDevelopment/api/v1/api.php
[Tue Jan 05 11:41:15.925963 2016] [rewrite:trace2] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c81030/initial] [perdir G:/xampp/htdocs/RESTDevelopment/] strip document_root prefix: G:/xampp/htdocs/RESTDevelopment/api/v1/api.php -> /RESTDevelopment/api/v1/api.php
[Tue Jan 05 11:41:15.925963 2016] [rewrite:trace1] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c81030/initial] [perdir G:/xampp/htdocs/RESTDevelopment/] internal redirect with /RESTDevelopment/api/v1/api.php [INTERNAL REDIRECT]
[Tue Jan 05 11:41:15.926963 2016] [rewrite:trace3] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c8b018/initial/redir#1] [perdir G:/xampp/htdocs/RESTDevelopment/] add path info postfix: G:/xampp/htdocs/RESTDevelopment/api -> G:/xampp/htdocs/RESTDevelopment/api/v1/api.php
[Tue Jan 05 11:41:15.926963 2016] [rewrite:trace3] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c8b018/initial/redir#1] [perdir G:/xampp/htdocs/RESTDevelopment/] strip per-dir prefix: G:/xampp/htdocs/RESTDevelopment/api/v1/api.php -> api/v1/api.php
[Tue Jan 05 11:41:15.926963 2016] [rewrite:trace3] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c8b018/initial/redir#1] [perdir G:/xampp/htdocs/RESTDevelopment/] applying pattern 'api/v1/(.*)$' to uri 'api/v1/api.php'
[Tue Jan 05 11:41:15.926963 2016] [rewrite:trace2] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c8b018/initial/redir#1] [perdir G:/xampp/htdocs/RESTDevelopment/] rewrite 'api/v1/api.php' -> 'api/v1/api.php?request=api.php'
[Tue Jan 05 11:41:15.926963 2016] [rewrite:trace3] [pid 6680:tid 1704] mod_rewrite.c(476): [client 10.1.10.70:54696] 10.1.10.70 - - [10.1.10.70/sid#604b00][rid#2c8b018/initial/redir#1] split uri=api/v1/api.php?request=api.php -> uri=api/v1/api.php, args=request=api.php&request=query/
在给出重定向错误之前,最后5行在日志中重复多次。
我尝试过的事情:
RewriteBase
设置为各个目录/文件夹以尝试确定它是否被重定向错误...我对此不太了解,所以我拍摄失明并且没有&# 39;工作。注意:我为此目录设置了AllowOverride All
。
感谢您的帮助!
答案 0 :(得分:1)
如果api/v1/
不是真正的路径,那么请使用此规则:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/v1/(.*)$ api.php?request=$1 [QSA,NC,L]