<div dir="ltr">Igor,<div>Thanks for the pointer however there is one last thing I'm not sure how to do.</div><div>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 on the REQUEST_URI.</div>
<div><br></div><div>Basically when I try to access <a href="http://www.domain.com/category">http://www.domain.com/category</a> - it should pass to index.php the request_uri /browse/category and then serve the appropriate output.</div>
<div>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</div><div><br></div><div>Cheers,</div><div><br></div><div><div>server {</div><div> listen *:80;</div>
<div> server_name <a href="http://www.domain.com">www.domain.com</a>;</div><div> access_log /var/www/domain/logs/access_log main;</div><div> error_log /var/www/domain/logs/error_log debug;</div><div>
root /var/www/domain/html/http;</div>
<div> index index.php;</div><div><br></div><div> if ($http_host !~ "^www\.domain\.com$") {</div><div> rewrite ^(.*) <a href="http://www.domain.com">http://www.domain.com</a>$1 permanent;</div>
<div> }</div><div><br></div><div> location / {</div><div> try_files $uri $uri/ /index.php?$args;</div><div> }</div><div> location /browse {</div><div> #rewrite ^/browse/(.*) <a href="http://www.domain.com/$1">http://www.domain.com/$1</a> permanent;</div>
<div> }</div><div> location /min {</div><div> try_files $uri $uri/ /min/index.php?q=;</div><div> }</div><div> location /blog {</div><div> try_files $uri $uri/ /blog/index.php?q=$1;</div>
<div> }</div><div> location /apc {</div><div> try_files $uri $uri/ /apc.php$args;</div><div> }</div><div><br></div><div> location ~ \.php {</div><div> include /etc/nginx/fastcgi_params;</div>
<div> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;</div><div> fastcgi_param PATH_INFO $fastcgi_script_name;</div><div> fastcgi_param SERVER_NAME $http_host;</div>
<div> fastcgi_pass <a href="http://127.0.0.1:9000">127.0.0.1:9000</a>;</div><div> }</div><div><br></div><div> location ~* ^.+\.(ht|svn)$ {</div><div> deny all;</div><div> }</div>
<div><br></div><div> # Static files location</div><div> location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {</div><div> expires max;</div>
<div> }</div><div>}</div></div><div><div dir="ltr"> </div><br>
<br><br><div class="gmail_quote">On Sun, May 22, 2011 at 08:21, Igor Sysoev <span dir="ltr"><<a href="mailto:igor@sysoev.ru">igor@sysoev.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Sun, May 22, 2011 at 03:41:59AM +0300, Adam Benayoun wrote:<br>
> Hello everyone,<br>
> I'm trying to setup some basic rewrite rules in nginx (I'm sorry if I may be<br>
> asking obvious question but I moved my servers from apache to nginx and I<br>
> can't figure out how to write simple rewrite rules in nginx).<br>
><br>
> This is what I am trying to achieve:<br>
><br>
> I have a URL with the following arguments:<br>
><br>
> <a href="http://www.domain.com/browse/category" target="_blank">http://www.domain.com/browse/category</a><br>
><br>
> What I want to achieve is:<br>
> - When someone try to reach <a href="http://www.domain.com/category" target="_blank">http://www.domain.com/category</a> - it will serve<br>
> the url <a href="http://www.domain.com/browse/category" target="_blank">http://www.domain.com/browse/category</a> internally (no 301 redirect).<br>
> - When someone will try to reach <a href="http://www.domain.com/browse/category" target="_blank">http://www.domain.com/browse/category</a> it<br>
> will redirect externally (301) to <a href="http://www.domain.com/category" target="_blank">http://www.domain.com/category</a><br>
><br>
> I've added 2 rewriterule at first but somehow only the first rule works, the<br>
> second won't work:<br>
><br>
> rewrite ^/browse/(.*) <a href="http://www.domain.com/$1" target="_blank">http://www.domain.com/$1</a> permanent;<br>
> rewrite ^/(category1|category2|category3|category4)$ /browse/$1<br>
> last;<br>
><br>
> Thanks (and sorry for asking a somewhat newbie question!)<br>
><br>
> p.s: yes, I've read this <a href="http://wiki.nginx.org/HttpRewriteModule" target="_blank">http://wiki.nginx.org/HttpRewriteModule</a><br>
<br>
</div></div>You should not read anyting about rewrite module. It's better to forget<br>
about it. You should think using locations.<br>
<br>
location /category1/<br>
#depending on processing method:<br>
<br>
# FastCGI<br>
fastcgi_pass backend;<br>
fatscgi_param SCRIPT_FILENMAE /path/to/browse;<br>
<br>
# proxying<br>
proxy_pass <a href="http://backend/browse/" target="_blank">http://backend/browse/</a><br>
<br>
# static files<br>
root /path/to/browse;<br>
}<br>
<br>
location /browse/ {<br>
rewrite ^/browse/(.*) /$1 permanent;<br>
}<br>
<font color="#888888"><br>
<br>
--<br>
Igor Sysoev<br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://nginx.org/mailman/listinfo/nginx" target="_blank">http://nginx.org/mailman/listinfo/nginx</a><br>
</font></blockquote></div><br></div></div>