nginx - 如何使用 Nginx 重写将 url 段转换为查询字符串

标签 nginx url-rewriting

我想要这个简单的重写规则:

http://example.com/8743b52063cd84097a65d1633f5c74f5?param1=999&param2=2222

重定向至:

http://example.com/index.php?param1=999&param2=2222&hash=8743b52063cd84097a65d1633f5c74f5

以下是我的默认位置:

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

如何使用 Nginx 重写来实现此目的?

最佳答案

使用 rewrite statement :

rewrite "^/(\w{32})$" /index.php?hash=$1 last;

或者,在location block内:

location ~ "^/(?<hash>\w{32})$" {
    rewrite ^ /index.php?hash=$hash last;
}

关于nginx - 如何使用 Nginx 重写将 url 段转换为查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43906896/

相关文章:

html - 如何在 Lift 框架中添加新页面

url-rewriting - ASP.NET Core RC2 中的 URL 重写

ubuntu - 无法在 Nginx 服务器上访问 phpMyAdmin

http - Nginx (1.2.7) 将 HTTP 重定向到 HTTPS

python - 使用 Nginx 作为 Sanic + Gunicorn 的反向代理时性能下降

apache - 不以点 html/php 结尾的 URL 的 RewriteRule

php - Wordpress - 在 url 中重写或隐藏 wp-json

javascript - 在 Nginx 或 Django 中安装 Prerender?

c - 如何在 nginx 中使用 c/c++ 模块

url-rewriting - Magento Enterprise url 重写与 url 重定向