Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx - redirect a certain path to another domain

I am very unfamiliar with nginx, as a forewarning, and also can't find any actual references on the regex system they use. So right now it's a black box to me.

All I want to do is redirect a user trying to go to www.mydomain.com/mydirectory/X to www.myotherdomain.com/X .

Seems like I should be using the rewrite command but the syntax of the regex is eluding me.

Thanks in advance.

like image 834
Eli Avatar asked Jun 10 '10 19:06

Eli


People also ask

How do I change my URL in NGINX?

NGINX Return directive The easiest and cleaner way to rewrite an URL can be done by using the return directive. The return directive must be declared in the server or location context by specifying the URL to be redirected.


1 Answers

I made a solution that works. I had it before posting this question but didn't realize I needed to restart nginx. Put the following inside your server block.

rewrite ^(/mydirectory/)(.*)$ http://www.myotherdomain.com/$2 permanent;
like image 68
Eli Avatar answered Oct 19 '22 14:10

Eli