Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

After a lot of googling, I've managed to get pretty URLs working by using:

server {
    listen   80;
    server_name  www.url.com;
    rewrite ^/(.*) http://url.com/$1 permanent;
}

server {
    listen   80;
    server_name url.com;

    access_log /var/www/url.com/logs/access.log;
    error_log /var/www/url.com/logs/error.log;

    location / {

    root   /var/www/url.com/public/;
    index  index.html index.htm index.php;
    include /etc/nginx/mime.types;

    try_files $uri $uri/ @extensionless-php;

    }

    location @extensionless-php {
        rewrite ^(.*)$ $1.php last;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/url.com/public$fastcgi_script_name;
    }

    location /blog {
        root /var/www/url.com/public;
        index index.php;
        try_files $uri $uri/ /blog/index.php?$args;
    }

}

It seems to work. However, for SEO purposes, I'd like to permanently redirect requests from url.com/filename.php to the new url.com/filename

I gather that I should be using rewrite ^/(.*)\.php$ http://url.com/$1 permanent; in the .php location block, but how do I do it without causing an endless loop?

share|improve this question
    
You should post at least the entire server block, so that it's possible to determine that nothing else is interfering with your desired behavior. –  Michael Hampton Feb 19 '13 at 4:38
    
Thanks for the tip - I've edited it to include the original full server block. –  nonchalant Feb 19 '13 at 4:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.