重写在不同的Web服务器上总是那些吸pipe,为我打破了驼背。
现在我在服务器configuration中有以下内容:
rewrite ^/(.+)$ /index.php?/$1 last;
现在,我需要确认,我在服务器上打开的任何URL都必须得到/ 。 但是,如果URL有参数,尾部/将被忽略。
url可能如下所示:
http://domain.tld/testing/ // is okay http://domain.tld/testing // should be redirected with trailing slash http://domain.tld/testing#param // should be left alone
我尝试了以下内容:
rewrite ^([^.\#]*[^/])$ /$1/ permanent; rewrite ^/(.+)$ /index.php?/$1 last;
但是它做了什么,它只留下带有斜线的url,但是如果一个url没有,那么它会redirect到http://domain.tld/index.php//testing/甚至是http://domain.tld/index.php//testing/#param使用参数时。
你不可以做这个。
以#开头的URL部分称为片段。 它永远不会发送到Web服务器。 当浏览器看到http://www.example.com/page#something ,会向http://www.example.com/page#something发送请求,然后使用#something从服务器接收的页面。
如果浏览器向http://www.example.com/page/#something发送请求,则会从服务器请求http://www.example.com/page/ 。
因此,您需要修复应用程序中的path,以避免像您所描述的问题发生。