4

Installed nginx and php 5.6 on a raspberry pi 2. Working wonderfully minus the fact that my pages still load from xyz.com/index.php/whatever (WRONG) aswell as xyz.com/whatever (PERFECT). I do NOT want /index.php to load my home page. I want it to redirect to / without the index.php. This goes for all subfolders aswell. What am I doing wrong?? This is the first server I've ever built so any help would be appreciated. Thanks.

sites available conf:

server {
    root /data/something.com/www/something/public;
    index index.php index.html index.htm;
    server_name something.com.local;    

    # Logging
    error_log /data/something.com/logs/error.log;
    access_log /data/something.com/logs/access.log;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    # Disallow access to hidden files
    location ~ /\. {
        deny all;
    }

    # Some locations will never contain PHP files, handle it in the server
    location ~ ^/(robots.txt|favicon.ico)(/|$) {
        try_files $uri =404;
    }

    # Pretty urls no /index.php (THIS IS WORKING...BUT /index.php is still accessible?)
    location / {
            try_files $uri $uri/ /index.php?$query_string;
    }

    # Remove trailing slash to please routing system.
    if (!-d $request_filename) {
            rewrite     ^/(.+)/$ /$1 permanent;
    }   

    error_page 404 /index.php;

    sendfile off;

    # PHP       
    location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include /etc/nginx/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # We don't need .ht files with nginx.
    location ~ /\.ht {
            deny all;
    }
}
Steve
  • 115
  • 7

1 Answers1

0

As explained in nginx redirect loop, remove index.php from url and similar to Remove index.php from Joomla! URLs with NGINX, you have to use a special trick to avoid a redirect loop when redirecting from index.php:

index index.php index.html index.htm;
if ($request_uri ~ "^/(.*)(?<=/)index\.php[/?]?((?<=[/?]).*)?$") {  return  301 /$1$2;  }
Community
  • 1
  • 1
cnst
  • 25,870
  • 6
  • 90
  • 122