Вторая редакция конфига для nginx

server {
        listen 80;
        server_name sitename.ru;
        rewrite ^(.*)$ http://www.sitename.ru$1 permanent;
}
server {
        listen 80;
        server_name www.sitename.ru;
        root /var/www/sitename.ru/www;
        autoindex off;

        rewrite ^(.*/)?([^\.]*[^/])$ $1$2/ permanent;
        rewrite ^(.*\.[^/]*)/$ $1 permanent;

        location = /favicon.ico {}
        location = /robots.txt {}
        location = /capsule/ext/kcaptcha/ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
        location ~ /capsule/ {}
        location ~ /share42/ {}
        location / {
                rewrite ^(.*)$ /index.php;
        }
        location = /index.php {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
        location ~ /\.ht {
                deny all;
        }
}