dongpai2754 2013-06-04 14:32
浏览 127
已采纳

在Nginx重写中将所有PHP请求重定向到路由器(Tonic Framework)

I've started working on a new RESTful API using the Tonic Framework. I already have functioning code that I've tested over my apache box, but I'm now trying to move it to my Nginx machine.

I've tried converting this to nginx rules:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !router\.php$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* router.php [L,QSA]
</IfModule>

But none of my rules seem to work.

What i've tried so far is Trying to redirect all requests to /v2/router.php (the php file im trying to get to)

location /v2/ {
    try_files $uri $uri/ /v2/router.php;
}

This causes weird results such as all of my php files executing for some weird reason, etc...

Would appreciate your support on this.

  • 写回答

1条回答 默认 最新

  • drh78568 2013-06-04 15:14
    关注

    You can try something like

    location /v2 {
        root <absolute folder path>/v2;
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /v2/router.php?/$1 last;
            break;
        }
    }
    

    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭