Nginx: Rewriting entire URI to query string

Posted by Doug on Server Fault See other posts from Server Fault or by Doug
Published on 2012-10-02T01:15:55Z Indexed on 2012/10/02 3:40 UTC
Read the original article Hit count: 378

Still pretty new to nginx here, trying to get a simple rewrite to work, but the server just responds '404 not found'

My server block

server {
listen   80;
listen   [::]:80;

server_name pics.example.com;
root /home/pics;

rewrite ^(.*)$ index.php?tag=$1;

location / {

    try_files $uri $uri/ $uri.php /index.html $uri =404;
    #try_files $uri =404;

    fastcgi_split_path_info ^([a-z]+)(/.+)$;
    include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/tmp/php5-fpm.sock;
    fastcgi_index index.php;
}

location /doc/ {
    alias /usr/share/doc/;
    autoindex on;
    allow 127.0.0.1;
    deny all;
}
}

pics.example.com/foobear should rewrite to pics.example.com/index.php?tag=foobear

© Server Fault or respective owner

Related posts about nginx

Related posts about redirect