I have been trying to rewrite my php pages so that they display without their extensions in the browser. For example, a link on my server at www.example.com loads a page called about-us.php and in the browser, the user would see www.example.com/about-us.
I have been trying to follow these tutorials to try and get this to work, but sadly they are not working.
Here is my nginx sites-available/default file content.
# Server Block
server {
# Listening Ports
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
# Root Location Initialization
root /home/zach/Documents/Workspaces/www;
index index.php index.html index.htm;
# Server Name
server_name localhost;
# Root Location
location / {
try_files $uri $uri/ @extensionless-php;
}
# Error pages
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/zach/Documents/Workspaces/www;
}
# PHP Handling
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Extensionless PHP
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
}
All of my links to php pages still display the .php extension in the browser, does anyone have any solutions to my problem?