我想用 slim 制作一个 api。它将位于我的“tools”子域中名为 api 的目录中。
http://tools.fifaguide.com/api
我的 .htaccess 文件应该是什么样子?
目前我的 .htaccess 位于我的 Wordpress 目录中(html -> .htaccess),它看起来像这样:
<IfModule mod_rewrite.c>
//my part
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/api/index.php
RewriteRule ^api/(.*) http://tools.fifaguide.com/api/index.php [L]
//wordpress part
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
问题是当我尝试
http://tools.fifaguide.com/api/hello/steve
我立即被重定向回 api/index.php,而不是停留在/api/hello/steve 并显示结果。
看起来 wordpress 正在导致这种情况发生,但我该如何防止它发生呢?
最佳答案
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/api/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ api/index.php [QSA,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
关于php - Slim Framework 与 WordPress 正确设置 htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17131155/