Transfer to a new domain? with url request? doesn't work. :( Help

I have this rewrite rule ...

Redirect all initial requests from world.example.com to 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]

      

Which works great. But some of my apps have ...

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

      

Unfortunately it does not redirect properly to web.example.com. Instead, it just goes to web.example.com with no query parameters.

How can I correctly redirect the request to web.example.com along with the request parameters?

Basically, what should he do ...

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

      

Just changing the world to the Internet and passing in the query string.

reference

+2


source to share


3 answers


You don't need to use a complicated rewrite mechanism for this. Just use Redirect

:

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

      



The directive Redirect

automatically saves everything that happens after the redirect.

+5


source


You forgot to use the "Query String Append" flag .[R=301,L,QSA]



+1


source


We can do this with Nginx too.

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;
}

      

Link:

0


source







All Articles