Nginx Rewrite: change only index location?

How can I send a user to a new location only if the user does not have a URI? I try to follow, but it does not work ... it always sends me to / newlocation

rewrite ^/$ http://www.domain.com/newlocation permanent; rewrite ^/(.*)$ http://www.domain.com/$1 permanent; 

So basically, I need:

If the user writes in the browser www.domain.org, he goes to the site www.domain.com/newlocation. If the user writes in the browser www.domain.org/something, he sends to the site www.domain.com/something

Thanks!

+4
source share
1 answer

I'm not sure why your current approach is not working. ^ / $ should match only /. Maybe this is something else the current configuration. Here is a server that should do what you need.

 server { server_name www.domain.org; # Only match requests for / location = / { rewrite ^ http://www.domain.com/newlocation permanent; } # Match everything else location / { rewrite ^ http://www.domain.com$request_uri? permanent; } } 
+10
source

All Articles