Frontend Developer
Hello,
I have a droplet and a website. I can upload my html files to my droplet and see them correctly.
But I just want to see my web pages like this; 12.34.556.708/home 12.34.556.708/about 12.34.556.708/test etc
and not like this; 12.34.556.708/home.html 12.34.556.708/about.asp 12.34.556.708/test.php etc
How can i do that? Is that possible with nginx settings?
I’ve tried a couple of configurations such as the one found on the link below -->
https://www.digitalocean.com/community/questions/about-url-extensions-at-nginx
and also a few others i found on stack-overflow. But all don’t seem to be working.
Is there an actual means to load webpages without their extensions showing?
P.S I’m a newbie to nginx Thank you.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @mxwlljr,
I think what you are looking for is the following
try_files $uri $uri/ $uri.html @extensionless =404;
Another possibility is @extensionless. @extensionless is treated like a normal file, and that’s because you’ve added an extra =404 after @extensionless within try_files – the @extensionless part would only work as the last parameter as an internal redirect to another context.
If you want not only to support handing requests without .html, but to also strip .php from any requests, you might want to do the following:
location / {
if (-e $request_filename.html){
rewrite ^/(.*)$ /$1.html;
}
}
location ~ \.html$ {
if ($request_uri ~ ^/([^?]*)\.html(\?.*)?$) {
return 302 /$1$2;
}
fastcgi_...
}
Regards, KFSys
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.