Welcome! Log In Create A New Profile

Advanced

Re: simple rewrite rules

May 22, 2011 01:24AM
On Sun, May 22, 2011 at 03:41:59AM +0300, Adam Benayoun wrote:
> Hello everyone,
> I'm trying to setup some basic rewrite rules in nginx (I'm sorry if I may be
> asking obvious question but I moved my servers from apache to nginx and I
> can't figure out how to write simple rewrite rules in nginx).
>
> This is what I am trying to achieve:
>
> I have a URL with the following arguments:
>
> http://www.domain.com/browse/category
>
> What I want to achieve is:
> - When someone try to reach http://www.domain.com/category - it will serve
> the url http://www.domain.com/browse/category internally (no 301 redirect).
> - When someone will try to reach http://www.domain.com/browse/category it
> will redirect externally (301) to http://www.domain.com/category
>
> I've added 2 rewriterule at first but somehow only the first rule works, the
> second won't work:
>
> rewrite ^/browse/(.*) http://www.domain.com/$1 permanent;
> rewrite ^/(category1|category2|category3|category4)$ /browse/$1
> last;
>
> Thanks (and sorry for asking a somewhat newbie question!)
>
> p.s: yes, I've read this http://wiki.nginx.org/HttpRewriteModule

You should not read anyting about rewrite module. It's better to forget
about it. You should think using locations.

location /category1/
#depending on processing method:

# FastCGI
fastcgi_pass backend;
fatscgi_param SCRIPT_FILENMAE /path/to/browse;

# proxying
proxy_pass http://backend/browse/

# static files
root /path/to/browse;
}

location /browse/ {
rewrite ^/browse/(.*) /$1 permanent;
}


--
Igor Sysoev

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

simple rewrite rules

Adam Benayoun May 21, 2011 08:44PM

Re: simple rewrite rules

Igor Sysoev May 22, 2011 01:24AM

Re: simple rewrite rules

Adam Benayoun May 22, 2011 03:52AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 311
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready