【发布时间】:2021-09-17 12:56:57
【问题描述】:
我需要在不更改浏览器 url 的情况下将 slug 重写为 nginx 中的查询字符串。
在 Apache 中以下工作:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/theblog/([0-9a-zA-Z-]+)$ /theblog/blog?slug=$1 [L,QSA]
在 nginx 中我尝试了以下两种方法:
rewrite ^\/theblog\/((?!blog?)[^\/]+)$ /theblog/blog?slug=$1 break;
rewrite ^\/theblog\/((?!blog?)[^\/]+)$ /theblog/blog?slug=$1 last;
他们都 REDIRECT 到 url 的查询字符串版本,“works”但不是我想要的。我不想更改浏览器中的网址。
我希望保留网址:http://example.com/theblog/test
不重定向到:http://example.com/theblog/blog?slug=test
即使那是被请求的资源。
该站点是静态 html,使用 javascript 获取数据,甚至没有为该域启用 php。
此服务器正在使用: Plesk 黑曜石 18.0.36 Nginx 1.20.1
希望这是有道理的。 任何帮助将不胜感激。
谢谢!
【问题讨论】:
标签: nginx url-rewriting