Remove .php extension in nginx using Valet for Windows

346 Views Asked by At

Looking to make my links go from example.com/page.php to example.com/page

I'm using Valet for Windows on a static website but can't seem to figure out how to configure my site.conf file, which looks like the following:

server {
    listen 80;
    server_name sp.test www.sp.test *.sp.test;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name sp.test www.sp.test *.sp.test;
    root /;
    charset utf-8;
    client_max_body_size 128M;

    location ~* /41c270e4-5535-4daa-b23e-c269744c2f45/([A-Z]+:)(.*) {
        internal;
        alias $1;
        try_files $2 $2/;
    }

    ssl_certificate "C:/Users/AJ/.config/valet/Certificates/sp.test.crt";
    ssl_certificate_key "C:/Users/AJ/.config/valet/Certificates/sp.test.key";

    location / {
        rewrite ^ "C:/Users/AJ/AppData/Roaming/Composer/vendor/cretueusebiu/valet-windows/server.php" last;
    }

    access_log off;
    error_log "C:/Users/AJ/.config/valet/Log/nginx-error.log";

    error_page 404 "C:/Users/AJ/AppData/Roaming/Composer/vendor/cretueusebiu/valet-windows/server.php";

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9001;
        fastcgi_index "C:/Users/AJ/AppData/Roaming/Composer/vendor/cretueusebiu/valet-windows/server.php";
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME "C:/Users/AJ/AppData/Roaming/Composer/vendor/cretueusebiu/valet-windows/server.php";
        fastcgi_param HOME 'C:/Users/AJ';
    }

    location ~ /\.ht {
        deny all;
    }
}

server {
    listen 60;
    server_name sp.test www.sp.test *.sp.test;
    root /;
    charset utf-8;
    client_max_body_size 128M;

    location ~* /41c270e4-5535-4daa-b23e-c269744c2f45/([A-Z]+:)(.*) {
        internal;
        alias $1;
        try_files $2 $2/;
    }

    location / {
        rewrite ^ "C:/Users/AJ/AppData/Roaming/Composer/vendor/cretueusebiu/valet-windows/server.php" last;
    }

    access_log off;
    error_log "C:/Users/AJ/.config/valet/Log/nginx-error.log";

    error_page 404 "C:/Users/AJ/AppData/Roaming/Composer/vendor/cretueusebiu/valet-windows/server.php";

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9001;
        fastcgi_index "C:/Users/AJ/AppData/Roaming/Composer/vendor/cretueusebiu/valet-windows/server.php";
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME "C:/Users/AJ/AppData/Roaming/Composer/vendor/cretueusebiu/valet-windows/server.php";
        fastcgi_param HOME 'C:/Users/AJ';
    }

    location ~ /\.ht {
        deny all;
    }
}

Based on some other answers on SO, I've tried the following to no avail:

location / {
    try_files $uri $uri.html $uri/ @extensionless-php;
    index index.html index.htm index.php;
}

location ~ \.php$ {
    try_files $uri =404;
}

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

I typically use apache / .htaccess, so editing a conf file is a little foreign to me, any ideas on what it could be?

0

There are 0 best solutions below