Removing index.php from url

adambenayoun nginx-forum at
Mon Dec 3 00:08:55 UTC 2012

Hey all,
I have a server with nginx 1.2.5 and php-fpm 5.3.3 installed. I have a web
application built on top of zend framework and the routing passes everything
thru a index.php file.
So while works - will fetch the same content aswell
and I'd like to get rid of it for SEO purpose.

Here's my configuration - right now there's a if statement that takes care
of removing the index.php however I know that if is evil and therefore
shouldn't be used. On top of that the only instance that won't work well is which in this case instead of redirecting to will just display a blank page with a 301 status code.

On top of that - if you guys spot any problem with my config - I'd love to
hear what I am doing wrong and what can be improved.

server {
listen *:80;
return 301 $scheme://$request_uri;
server {
listen 80;
listen 443 ssl;
ssl_certificate /etc/nginx/certs/;
ssl_certificate_key /etc/nginx/certs/;
error_log /var/www/domain/logs/error_log warn;
root /var/www/domain/html/http;
index index.php;
client_max_body_size 150m;
error_page 403 404;

if ( $request_uri ~ "^/index.php" ) {
rewrite ^/index.php(.*) $1 permanent;
location / {
rewrite ^/wanted/feed$ /feed?filter=wanted permanent;
try_files $uri $uri/ /index.php?$args;
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 HTTPS $https if_not_empty;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SERVER_NAME $http_host;
location ~* ^.+\.(ht|svn|git)$ {
deny all;

# Static files location
location ~*
expires max;

Posted at Nginx Forum:,233476,233476#msg-233476

More information about the nginx mailing list