I'm new, first time I made a site... please help?

vortex10

New Member
Messages
1
Reaction score
0
Points
1
hi and good day,

Sir, Ma'am

How can I hide my index.html and all the pages with .html extensions?

I spent 4 hours looking for a solution but until now nothing works. I added a .htaccess to the public and add this code

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

It still doesn't hide the index.html and .html extensions


please help

kind regards and Good day,
 

jensen

Active Member
Messages
1,167
Reaction score
22
Points
38
not sure why one would hide the index.html as it's the first file the browsers look for?
could you share why? keen to learn new stuff everyday.
 

caftpx10

Well-Known Member
Messages
1,534
Reaction score
114
Points
63
not sure why one would hide the index.html as it's the first file the browsers look for?
The web server would be the one looking for such files. By default, Apache's configuration is set to look out for index files such as 'index.html' (and 'index.php' after installation of PHP, they have priority and can be configured to be something other than having the 'index' prefix) in replacement of the index directory listing that it would fall back to.

If you want to lie about the existence of '.html' files then you could throw out a 404 header along with setting a custom 404 page to use. If you go that way then I would also apply the same custom 404 to the entire site (if an actual file or directory doesn't exist) so that it better blends in.

In regards to directory indexing, you might want to turn that off if you are trying to hide files.

If what you are really looking for is to at least block access effectively to files with the '.html' file extension then you could go with the following in the '.htaccess file'..
Code:
<FilesMatch "/^(.*?)\.html/">
    Order Allow,Deny
    Deny from all
</FilesMatch>
This would throw out a 403 (forbidden).
Note that I have not checked if the RegEx used is valid so you might have to try to figure that out.
 
Top