php - Slim Framework 与 WordPress 正确设置 htaccess

标签 php wordpress .htaccess mod-rewrite slim

我想用 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/

相关文章:

css - Woocommerce 产品列表间距

php - 将值设置为 NULL 而不是 'NULL'

javascript - 如何检查pdf文件是否存在?

php - 如何解析和抓取WordPress的内容

.htaccess - 如何使用 .htaccess 文件默认提供 somefile.pdf 而不是 index.html ?

.htaccess - 重定向旧静态移动网站的最佳实践

php - 使用 .do 扩展名作为所有 php 文件的 .php 扩展名

php - SQL:如何按满足某些条件的字段之和进行排序?

javascript - Ajax 上传不工作 codeigniter

javascript - 如何在自定义页面(而不是商店/产品页面)上添加“添加到购物车”按钮 Woocommerce