<div dir="ltr">Hello everyone,<div>I&#39;m trying to setup some basic rewrite rules in nginx (I&#39;m sorry if I may be asking obvious question but I moved my servers from apache to nginx and I can&#39;t figure out how to write simple rewrite rules in nginx).</div>

<div><br></div><div>This is what I am trying to achieve:<br><br>
</div><div>I have a URL with the following arguments:</div><div><br></div><div><a href="http://www.domain.com/browse/category">http://www.domain.com/browse/category</a></div><div><br></div><div>What I want to achieve is:</div>

<div>- When someone try to reach <a href="http://www.domain.com/category">http://www.domain.com/category</a> - it will serve the url <a href="http://www.domain.com/browse/category">http://www.domain.com/browse/category</a> internally (no 301 redirect).</div>

<div>- When someone will try to reach <a href="http://www.domain.com/browse/category">http://www.domain.com/browse/category</a> it will redirect externally (301) to <a href="http://www.domain.com/category">http://www.domain.com/category</a> </div>

<div><br></div><div>I&#39;ve added 2 rewriterule at first but somehow only the first rule works, the second won&#39;t work:</div><div><br></div><div><div>        rewrite ^/browse/(.*) <a href="http://www.domain.com/$1">http://www.domain.com/$1</a> permanent;</div>

<div>        rewrite ^/(category1|category2|category3|category4)$    /browse/$1 last;</div></div><div><br></div><div>Thanks (and sorry for asking a somewhat newbie question!)</div><div><br></div><div>p.s: yes, I&#39;ve read this <a href="http://wiki.nginx.org/HttpRewriteModule">http://wiki.nginx.org/HttpRewriteModule</a></div>

</div>