用nginx重定向动态URL

发布于 2025-02-01 12:07:54 字数 690 浏览 2 评论 0原文

在我的网站上,我有这样的链接:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文