我们在我们的网站上使用了一个embedded式的电子商务商店,它通过将所需的JS脚本添加到/shop页面来工作。 在服务器端,现在的要求是,计划/shop/anything所有URL /shop/anything被重写到/shop为服务器/shop ,因为该部分的其余部分是由embedded式JS商店处理的。
我不能写这个, rewrite or internal redirection cycle while processing "/shop正在进行rewrite or internal redirection cycle while processing "/shop我认为这只是对正则expression式的处理,但我似乎无能为力。
我的设置如下:
server { listen 8002 default_server; listen [::]:8002 default_server; location / { root /home/mysite; rewrite ^/shop/.+$ /shop; index index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; try_files $uri $uri/ /index.php?$query_string; set $path_info $fastcgi_path_info; fastcgi_param PATH_INFO $path_info; fastcgi_index index.php; include fastcgi_params; fastcgi_pass unix:/run/php/php7.0-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; } }
我也试过rewrite ^/shop/.*$ /shop; 但结果是一样的。 :|
通常所有的URL都是由/home/mysite (实际上是框架的入口脚本)的index.php文件处理的,但是我需要/shop之后的URL不是由PHP框架处理,而是由JSembedded/shop 。
什么是正确的方法来做到这一点?
==更新==
我碰巧和ECWID的一位支持开发人员交谈。 虽然他们没有任何Nginx的例子,但他们能够提供一个Apache代码片段。 我希望这有助于:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /~makfruit/shop/ RewriteRule ^([^\.]+)$ . </IfModule>
redirect周期的一个可能的原因是您在重写规则中缺lessbreak参数。 所以,你的rewrite行应该是这样的:
rewrite ^/shop/.+$ /shop break;
我能够使它在框架级别上工作。 我所做的只是将任何匹配/shop/anything任何url发送到处理/shop的相同控制器function。 我不知道为什么Nginx重写不起作用。 我接受这个作为closures这个线程的答案。