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

在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.

图片转代码服务由CSDN问答提供 功能建议

我开始使用Tonic Framework开发一个新的RESTful API。 我已经有了正常运行的代码 已经在我的apache盒子上进行了测试,但我现在正试图将它移动到我的Nginx机器上。

我尝试将其转换为nginx规则:

 &lt; IfModule mod_rewrite.c&gt; 
 RewriteEngine On 
 RewriteCond%{REQUEST_URI}!router \ .php $ 
 RewriteCond%{REQUEST_FILENAME}!-f 
 RewriteRule。* router.php [L  ,QSA] 
&lt; / IfModule&gt; 
   
 
 

但我的规则似乎都不起作用。

到目前为止,我尝试将所有请求重定向到/v2/router.php(即将尝试访问的php文件) < pre> location / v2 / { try_files $ uri $ uri / /v2/router.php; }

nn

这导致奇怪的结果如此 因为我的所有php文件都是出于某种奇怪的原因而执行等等...

非常感谢您对此的支持。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题