Tutorial :Rewrite to a new domain? with url query? not working. :( help


I have this rewrite rule...

Redirect all initial request 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 applications has...


Unfortunately, it is not being redirected properly to web.example.com. Instead, it just goes to web.example.com without the query params.

How could I make all request redirect properly to web.example.com along with the query params?

Basically, what it should do...

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

Just changing the world to web and passing the query string.



You don't need to use the complicated rewrite engine to do this. Just use Redirect:

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

The Redirect directive automatically preserves everything that comes after what you're redirecting.


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


We can do it 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;  }  


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »