.htaccess config for accessing files without extentions | Sololearn: Learn to code for FREE!


.htaccess config for accessing files without extentions

In apache server, I want to access the files without extention. For eg: Client Request URL is: http://myserver/filename.html Server Response would be: 404-Not Found Client Request is: http://myserver/filename Server Response would be: 200-display file I have a .htaccess config: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html But problem with this configuration is that, it doesn't return 404-error-code when, client requests file with a extention. Thanks... I hope, I'll get helped soon possible.

6/30/2019 2:26:45 PM


9 Answers

New Answer


David Carroll Yes


🤨😥 I'm not getting my answer!!


@Chris Latham I get 404 on requesting both of following URL in the browser after appending the script you gave, in the above script I have. RequestURL: http://mylocalsite/myfile Response-Code: 404 RequestURL: http://mylocalsite/myfile.html Response-Code: 404


Is the same HTTP Response being served back for both Request URL variations?


David Carroll is busy or if he free he will surely try to figure out Don't feel bad


Chris Latham I will try that and respond you


https://www.askapache.com/htaccess/using-filesmatch-and-files-in-htaccess/ I Got the Solution


Space {{#always_smile_ignore_situation😃😃}} Wow... you're name is changing so much and it's so long. Anyway... sorry for not responding yet. I actually lost track and have been so busy this week. I'll try to answer today.


I'm thinking that adding something along the lines of the following to your existing .htaccess might work. I don't have a server set up right now to test though. RedirectMatch 404 ^(.*).html