小编kmi*_*ndi的帖子

如何使用 nginx 将请求重定向到不同的域/url

我正在尝试将所有访问 URL“ http://example.com/something ”的用户重定向到像“ http://answares.com/examples_com/something ”这样的 URL 。

我正在尝试使用这样的代码:

server {
  listen 1.2.3.4:80;
  server_name "example.com";
  rewrite ^(.*) http://answares.com/examples_com$1 permanent;
}
Run Code Online (Sandbox Code Playgroud)

通过访问“ http://example.com/ ”我被重定向到“ http://answares.com/examples_com/ ”,但是通过访问“ http://example.com/something ”我被重定向到:“ http ://answares.com/something ”。

我尝试以不同的方式做到这一点,但我得到的最好的是:

http://answares.com/examples_com//something
Run Code Online (Sandbox Code Playgroud)

因为这两个斜线看起来很蹩脚。我在 Ubuntu 10.4 上使用 Nginx 0.7.65

rewrite nginx redirect

14
推荐指数
3
解决办法
11万
查看次数

标签 统计

nginx ×1

redirect ×1

rewrite ×1