Laravel 5 nginx domain.com/index.php and domain.com/ work. How to redirect / index.php?

Installed nginx and php 5.6 on raspberry pi 2. We work perfectly, bypassing the fact that my pages are still loaded from xyz.com/index.php/whatever (WRONG), as well as xyz.com/whatever (PERFECT). I do NOT want /index.php to load my homepage. I want it to redirect / without index.php. This applies to all subfolders. What am I doing wrong?? This is the first server I've ever created, so any help would be appreciated. Thanks.

available conf sites:

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;
    }
}
+4
source share
1 answer

nginx redirect loop, index.php URL- index.php Joomla! URL NGINX, , index.php:

index index.php index.html index.htm;
if ($request_uri ~ "^/(.*)(?<=/)index\.php[/?]?((?<=[/?]).*)?$") {  return  301 /$1$2;  }
0

Source: https://habr.com/ru/post/1606998/


All Articles