Hide ALL file extensions from URL with .htaccess

185 Views Asked by At

I want to hide all file extensions from the URL with .htaccess without defining each extension in the .htaccess. I have found a few options out there using mod_rewrite and mod_negotiation, but either they are incomplete or not explained well. I'd prefer not to simply copy and paste but also understand.

Here are a list of desired results:

  • Removal of all file extensions for the URL when visiting, be that html, php, css, jpg, etc... We do not want to have to define each one in .htaccess.

  • Have all files still load without their extensions

  • If the index of a directory or only file in the directly, root or otherwise, simply display the folder for example example.tld/onlyfile.ext -> example.tld or example.tld/directory/onlyfile.ext -> example.tld/directory/

  • When navigating to a file, add a trailing slash for example example.tld/somefile.ext -> example.tld/somefile/

If this is not possible it would be nice to hear that rather than just another repeat of how to redirect each individual extension.

Thanks for any help!

0

There are 0 best solutions below