Simple rewrite rules

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
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:

What I want to achieve is:

I’ve added 2 rewriterule at first but somehow only the first rule works,
second won’t work:

    rewrite ^/browse/(.*)$1 permanent;
    rewrite ^/(category1|category2|category3|category4)$ 


Thanks (and sorry for asking a somewhat newbie question!)

p.s: yes, I’ve read this

On Sun, May 22, 2011 at 03:41:59AM +0300, Adam Benayoun wrote:

    rewrite ^/(category1|category2|category3|category4)$    /browse/$1


Thanks (and sorry for asking a somewhat newbie question!)

p.s: yes, I’ve read this

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 S.

Thanks for the pointer however there is one last thing I’m not sure how
Basically my application is built on top of a framework meaning that
everything should go through index.php and then the routers configured
appropriately should serve you different templates and controllers based

Basically when I try to access - it
pass to index.php the request_uri /browse/category and then serve the
appropriate output.
This is how my config look like, let me know if that make sense and what
should I add to mimic that request_uri through index.php


server {
listen *:80;
access_log /var/www/domain/logs/access_log main;
error_log /var/www/domain/logs/error_log debug;
root /var/www/domain/html/http;
index index.php;

    if ($http_host !~ "^www\.domain\.com$") {
            rewrite  ^(.*)$1 permanent;

    location / {
            try_files $uri $uri/ /index.php?$args;
    location /browse {
            #rewrite ^/browse/(.*)$1 

location /min {
try_files $uri $uri/ /min/index.php?q=;
location /blog {
try_files $uri $uri/ /blog/index.php?q=$1;
location /apc {
try_files $uri $uri/ /apc.php$args;

    location ~ \.php {
            include /etc/nginx/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME

fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SERVER_NAME $http_host;

    location ~* ^.+\.(ht|svn)$ {
            deny  all;

    # Static files location
    location ~*

expires max;