2

我有这个重写规则...

将所有初始请求从 world.example.com 重定向到 web.example.com

RewriteCond %{HTTP_HOST} ^world\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^(.*)$ https://web.example.com$1 [R=301,L]

效果很好。但是,我的一些应用程序...

https://world.example.com/approvals/?id=b47b5256567

不幸的是,它没有正确重定向到 web.example.com。相反,它只是在没有查询参数的情况下进入 web.example.com。

如何使所有请求连同查询参数一起正确重定向到 web.example.com?

基本上,它应该做什么......

https://world.example.com/approvals/?id=b47b5256567
then
https://web.example.com/approvals/?id=b47b5256567

只需将世界更改为 web 并传递查询字符串。

帮助

4

3 回答 3

5

您不需要使用复杂的重写引擎来执行此操作。只需使用Redirect

<VirtualHost *>
    ServerName world.example.com
    Redirect permanent / https://web.example.com/
</VirtualHost>

Redirect指令会自动保留您重定向后的所有内容。

于 2009-08-28T01:33:04.110 回答
1

您忘记使用“Query String Append”标志。[R=301,L,QSA]

于 2009-08-28T01:31:35.487 回答
0

我们也可以用 Nginx 做到这一点。

server {
  listen 80:
  server_name: world.example.com    

  # URL redirect
  #rewrite ^ http://web.example.com$request_uri? permanent;
  rewrite ^ $scheme://web.example.com$request_uri permanent;
  #rewrite ^ $scheme://web.example.com permanent;
  #rewrite ^ $scheme://web.example.com;
}

参考:

于 2014-12-02T02:19:46.300 回答