Index.html works from htdocs but not in sub folder

My best guess the other issues started when you un-comment the other “RewriteEngine On” statement.

image

Best practice is one “RewriteEngine On” per .htaccess

2 Likes

thanks for your reply and now I am understanding what broke but right now my htaccess file only has 3 lines in it

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

These 3 above lines are commented and I can access index.html from my sub folder without having to type in index.html into my path. The above code allows one to type in a file without the .html extension but when I uncomment the 3 lines the html extension does not appear as intended but now index.html in sub folder throws a 403 error. So we fixed issue number one but when I use this rewrite directive in issue number 2 then now issue number one is broken again

Ok, so this is what you would follow for that. I am mainly linking this so you can read the text hi-lighted in red.

https://tinkertechlab.com/webhosting/htaccess/remove-file-extensions

Wait, so what is the second issue? As far as I understand it, these are the two things you wanted:

  1. index.html to work in sub folders (This works as soon as you remove the relevant htaccess files that are messing it up)
  2. The html extension to not appear

So these should be the ONLY three lines in your htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
2 Likes

Thanks so much for your patience!! Yes these are the 2 issues, You have it correct, so the following needs to work (both at the same time, not one or the other)

https://cookiefreecoders.com/Java/
and
https://cookiefreecoders.com/Java/JDBC where JDBC is a file with no html extension

I did as u suggested in htaccess, and cleared my cache
the following now happens

https://cookiefreecoders.com/JDBC …this pulls up the JDBC file with no extension
https://cookiefreecoders.com/Java/JDBC …this also works with no extension
https://cookiefreecoders.com/Java/ …now shows 403 error and i need it to default to the index.html page

so now when we fix issue 2 then issue 1 is broken again. Maybe the trailing slash has something to do with it

maybe we also need
RewriteCond %{REQUEST_FILENAME} !-d in addition to !-f
because we are dealing with both directory and file, just guessing
maybe it now thinks /Java/ is a file instead of a directory so it forbids access

also maybe we need a .* in the rule but am very confused at the moment

with no rewrite rule issue number 1 does work

PS: trailing slash means it is a directory and no trailing slash means it is a file

Ok, can you share the contents of the following three htaccess files? If they don’t exist, just say that, no need to create it.

  1. The htaccess file OUTSIDE the htdocs folder
  2. The htaccess file in the htdocs folder
  3. The htaccess file located in /htdocs/Java/
2 Likes

1

##################################################
#
# DO NOT EDIT THIS FILE
#
# Create a new .htaccess file in your htdocs
# directory (or example.com/htdocs/ directory)
# to add your own rules or override these rules.
#
##################################################


DirectoryIndex index.php index.html index.htm index2.html

ErrorDocument 403 https://errors.infinityfree.net/errors/403/
ErrorDocument 404 https://errors.infinityfree.net/errors/404/
ErrorDocument 500 https://errors.infinityfree.net/errors/500/

2

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

3
I do not have an htaccess file here, do I need 1?

user name is epiz_32679036

when I add the following rewrite rule a 403 error appears only in my subfolder.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]

accessing main/subfolder/file without html extension works correctly per above directive
but
accessing main/subfolder/ produces 403… there is an index.html present in the subfolder but access is forbidden

thanks in advance for your help

Please don’t create multiple topics on the same issue.

Thanks

5 Likes

Thanks guys very much for your help. After playing around a bit I solved my problem. It was as simple as just adding an htaccess to my subfolder. I am not sure why this worked but it did.