0

I have the current rule for my nginx routes:

        listen   80;
        server_name  www.domain1.com;
        rewrite ^/(.*) http://domain1.com/$1 permanent;

This works but only for the root path and not other routes. For example, a route like www.domain1.com/users/1 gets redirected to domain1.com. How do ensure that www.domain1.com/users/1 gets routes to domain1.com/users/1?

I got this to work by adding a '$' at the end:

rewrite ^/(.*)$ http://your_domain.com/$1 permanent;

TenJack
  • 193
  • 2
  • 7

1 Answers1

1

The rewrite you have there actually should work. That said, you don't need the capture at all as Nginx has already done that for you. You can just use

rewrite ^ http://domain1.com$request_uri? permanent;
Martin Fjordvald
  • 7,589
  • 1
  • 28
  • 35