redirect - Nginx 重定向仅更改域后 URL 的第一部分

标签 redirect nginx

我只想更改一组页面上 url 的第一部分。

例如。

domain.com/change/this/that/other 

domain.com/changed/this/that/other 

在这个例子中,包括这个在内的所有内容都是动态的

我觉得这行得通

location ~* ^/change/(.*)$ {rewrite ^ http://domain.com/changed/$1 permanent; break;}

但没有

最佳答案

正则表达式捕获变量与重写 block 本身有关。

location ~* ^/change/(.*)$ {
     rewrite ^/change/(.*)$ http://example.com/changed/$1 permanent; 
     break;
}

你可以看到例子:http://nginx.org/en/docs/http/ngx_http_rewrite_module.html

关于redirect - Nginx 重定向仅更改域后 URL 的第一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32462739/

相关文章:

php - 在 cookie 中为我的每个未登录用户提供唯一的 session ID

php - 使用 nginx 和 php7 无法加载任何 PHP 文件或在日志中看到任何错误

html - 如何向此按钮添加表单操作?

javascript - jquery查找并替换iframe src

.htaccess - htaccess 从不再存在的文件永久重定向

Javascript 重定向和成功调用函数

jsp - 重定向到空字符串时 Tomcat 中的行为发生变化

node.js - 将请求从静态包代理到 Express 后端时,NginX 无法传递 POST 请求正文

http - 如何设置 Cloudflare 防火墙以阻止假冒的 Google 机器人

elasticsearch - Kibana仪表板中的用户级别访问控制