Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache mod_重写Restful api_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache mod_重写Restful api

Apache mod_重写Restful api,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我的restful webapp中的correct.htaccess出现问题。我的REST api代码可以通过URL模式*/api/**访问,该模式应重定向到api文件夹中的index.php 所有其他URL(静态文件除外)应重定向到根文件夹中的index.html 我有以下文件夹结构: - api -- application/... -- vendor/... -- index.php - public -- css/... -- js/... - index.html - .htacces

我的restful webapp中的correct.htaccess出现问题。我的REST api代码可以通过URL模式*/api/**访问,该模式应重定向到api文件夹中的index.php

所有其他URL(静态文件除外)应重定向到根文件夹中的index.html

我有以下文件夹结构:

- api -- application/... -- vendor/... -- index.php - public -- css/... -- js/... - index.html - .htaccess 我尝试将另一个.htaccess添加到api文件夹,以使用/api/*重定向URL,但没有成功。所以我尝试用上面.htaccess中的规则重定向它

我认为较低的规则可能是正确的。因为重定向正在按预期工作。但是/api/规则不起作用。看起来请求也被重定向到index.html


我缺少什么?

尝试以下规则:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !^/api/index\.php$ [NC]
RewriteCond %{REQUEST_URI} ^/api [NC]
RewriteRule ^api/.* /api/index.php$ [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l # to check for symbolic links
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.html [L]

RewriteRule . - [L]

您需要对正则表达式模式进行细微调整:

DirectoryIndex index.php index.html
Options +FollowSymLinks
RewriteEngine on

# redirect all api calls to /api/index.php
RewriteRule ^api/((?!index\.php$).+)$ api/index.php [L,NC]

# If the request is a file, folder or symlink that exists, serve it up
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# otherwise, serve your index.html app
RewriteRule ^(.+)$ index.html [L]

从结果路径中删除
$
我在Rest API中遇到一些问题,如果我尝试->abc.com/API/Rest/products?limit=2我的站点返回404页错误,我如何解决这个问题,以及如何使用Rest API@Georg获取产品Leber@Rathinam请在上创建一个新问题,以便更详细地显示您的问题。这可能有几个问题,在评论中无法讨论(例如,服务器端映射如何,…)@Georgeber ye,有人已经发布了这篇文章->这也适用于我的情况,我的引导PHP文件包含在
/api
文件夹中,但我一直在努力让重写正确。我开始认为API重写中的
DirectoryIndex
和显式匹配
index.php
是这里的秘密。谢谢@anubhava我在Rest API中遇到了一些问题,如果我尝试->abc.com/API/Rest/products?limit=2我的站点返回404页面错误,我如何解决这个问题,以及如何使用Rest API获得产品,你能帮忙吗@anubhava zus被更新了问题,比如我到底需要什么?你能帮我吗?@Rathinam:看起来这是magento配置问题,而不是mod_重写问题。不幸的是,我对magento知之甚少。
DirectoryIndex index.php index.html
Options +FollowSymLinks
RewriteEngine on

# redirect all api calls to /api/index.php
RewriteRule ^api/((?!index\.php$).+)$ api/index.php [L,NC]

# If the request is a file, folder or symlink that exists, serve it up
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# otherwise, serve your index.html app
RewriteRule ^(.+)$ index.html [L]