I have a file and folder with the same name with dropping file extensions

Posted April 5, 2021 191 views

I know that I can fix my .htaccess I just dont have any knowledge on .htaccess:

DirectorySlash Off
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]

ErrorDocument 404 /404.html
ErrorDocument 403 /403.html

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @Filice,

I’m not sure I understand the question exactly. What I understand is that you wish your website to load without using the file’s extensions. For example, if you have a and someone loads the contact.php form to look like, is that correct?

Removing Extensions

To remove the .php extension from a PHP file for example to you have to add the following code inside the .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

If you want to remove the .html extension from a html file for example to you simply have to change the last line from the code above, to match the filename:

RewriteRule ^([^\.]+)$ $1.html [NC,L]


  • The problem that Im facing right now is that when I make a folder with the same name as a file like folder: images file: images.html, It will just go to the index of that directory, or for me, I made it so it goes to 403 because I disabled indexes. I have it so it gets rid of file extensions.

    • Hi @Filice,

      Did you try replacing your .htaccess code with what my suggestion above, did it work or it got you to the above issue you are describing?

      • I am not trying to get rid of file extensions as I already have that in my .htaccess. What Im trying to elucidate is that when making a folder with the same name as a html file, it goes to the folders index.

        file: "example.html"
        folder: "example"
        Going to "" redirects to the folders index.

        You were talking about getting rid of file extensions but I already have that, its working but the problem is, is when going to the it redirects to the index of example folder instead of the example html file. Having no extensions causes this problem as they both have the same name.