用nginx重定向动态URL
在我的网站上,我有这样的链接:
https://example.com/blog/some-text
因此,由于我的路径结构,代码必须这样读取它们:
https://example.com/blog/_entry.php?title= some-text
我该怎么做?例如,使用Apache和.htacces,您只需要做:
重写 ^blog/([\ da-z-]+)$ blog/_entry.php?title = $ 1 [l,nc]
在nginx中,我无法使其与服务器块一起使用。我尝试了很多不同的方法,但是那时都没有奏效,我尝试了以下几种类似的事情:
位置 /博客{ 重写 ^/blog/([\ da-z-]+)$ /blog/_entry.php?title=jum1 break; }
但是,当您转到https://example.com/blog/some-text
下载文件而不是打开文件时,其他解决方案也不适用于我
In my website i have links like this:
https://example.com/blog/some-text
So due to the structure of my paths, the code has to read them like this:
https://example.com/blog/_entry.php?title=some-text
What can i do to transform it? For example, with Apache and .htacces you just have to do:
RewriteRule ^blog/([\da-z-]+)$ blog/_entry.php?title=$1 [L,NC]
In nginx i can't get it to work with the server block. I have tried so many different ways but none of then have worked, i tried something like the following:
location /blog { rewrite ^/blog/([\da-z-]+)$ /blog/_entry.php?title=$1 break; }
But when you go to https://example.com/blog/some-text
it downloads the file instead of opening it, other solutions have not worked for me either
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论