0

I need some help to convert .htaccess apache rewrite to Nginx.

My WordPress website has this URL structure:

https://domain.com/our-office/laos/

And I need to change to:

https://domain.com/laos/

I did that easily with Apache and .htaccess with:

Redirect 301 /our-office/laos /laos/

But now that I moved to Nginx, I cannot get the same results.

Thanks.

Daniel
  • 193
  • 1
  • 6

1 Answers1

1

You can use rewrite with 'permanent' keyword, for example:

rewrite  ^/our-office/laos/(.*)$  https://domain.com/laos/$1 permanent;
Jakov Sosic
  • 5,267
  • 4
  • 24
  • 35
  • Note that the `return` directive can also be used. I'm not completely clear on when which should be used and why, but there is a discussion on [Taxing Rewrites](http://wiki.nginx.org/Pitfalls#Taxing_Rewrites) at nginx.org. – Paul Nov 29 '14 at 18:27
  • @Paul There's no reason to use it there. The return directive should be used when a rewrite is not necessary, i.e. when no specific part of the original URI is captured. In this case he can't use a return directly because a subpart needs to be extracted. He would need a map and a location and so it's better for concision to use a rewrite alone – Xavier Lucas Nov 30 '14 at 12:46