我在正确的.htaccess问题上停留在我宁静的webapp中。我的REST api代码应该可以通过URL模式*/api/**访问,它应该被重定向到index.php在api文件夹中。Apache mod_rewrite Restful api
所有其他URL(静态文件除外)应重定向到根文件夹中的index.html。
我有以下文件夹结构:
- api -- application/... -- vendor/... -- index.php - public -- css/... -- js/... - index.html - .htaccess
,这是我的.htaccess内容:
Options +FollowSymLinks
RewriteEngine on
# redirect all api calls to /api/index.php
RewriteCond "%{REQUEST_URI}" "^/api"
RewriteRule "^/api/(.+)$" "/api/index.php$" [QSA,L]
# If the request is a file, folder or symlink that exists, serve it up
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)$ - [S=1]
# otherwise, serve your index.html app
RewriteRule ^(.+)$ /index.html [L]
我尝试另一个的.htaccess添加到API文件夹重定向与网址/ api/*但没有任何成功。所以我试图用上面的.htaccess中的规则重定向它。
我认为规则可能是正确的。因为重定向工作正常。但是/ api /规则不起作用。看来这些请求也被重定向到index.html
我错过了什么?
删除'$'从得到的路径 – Deadooshka