Serve files and folders with the same name

SYSTEM INFORMATION
OS type and version Rocky Linux 9.5
Virtualmin version 7.30
Apache version 2.4

I have a VPS with a domain and a subdomain running right now.

In the subdomain I have HTML files and folders (it’s a static site), and I can access almost all web pages without problems, but I can’t access pages that share the same name with folders.

Real example: inside the folder “p” there are the folder “cv” and the file “cv.html”:

p/
├─cv/
└─cv.html.

The cv.html page links to documents contained in the “cv” folder, but the server does not allow me to access the address:

[SUBDOMAIN].[DOMAIN]/p/cv

Instead, it redirects me to:

[SUBDOMAIN].[DOMAIN]/p/cv/

And returns the “403 Forbiddden” error:

“Forbidden
You don’t have permission to access this resource. Server unable to read htaccess file, denying access to be safe”

What I understand is that if I want to access a file, without adding the file extension, and its name is the same as the name of a folder within the same directory, the server will try to open the folder, not the file, because when I add the file extension to the URL:

[SUBDOMAIN].[DOMAIN]/p/cv.html

The web page is displayed without problems.

My question is: how can I configure Virtualmin to, by default, open the addresses as files without file extensions? or what other options do I have (apart from renaming affected files/folders which, in my case, would not be ideal)?

You need a RewriteRule, either in the Apache VirtualHost or in the .htaccess file in the document root.

https://stackoverflow.com/questions/16919526/how-to-link-to-pages-without-the-html-extension

I checked the StackOverflow solution, and I have inserted the following lines:

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

in the .htaccess file (which only contained a rule for the 404 page), located in the root folder of my subdomain, with no result.

I also tried in the httpd.conf file (via Virtualmin > Web Configuration > Configure website AND Configure SSL website > Edit Directives). I inserted them under the “RewriteEngine on” section, with no results.

I tried opening the affected page in private tabs, to avoid cache problems, but it’s the same.

I want to mention that I could already access my pages without adding the file extension (I did this through Virtualmin), I just can’t access the ones that share their name with a folder.

Any idea what I’m doing wrong, or what I’m not doing?

what is it exactly you want, perhaps a generic way to browse all the random files in a directory?

generally speaking, when using apache, the config line

DirectoryIndex index.html

one with several file options

DirectoryIndex index.html index.htm index.php index.php4 index.php5

will determine what you see (html-wise) when you only have a directory name at the end of your URL.

hope this helps a little.

Hi. What I want is that when accessing a web page, the server directs the user to that web page (the expected behavior), and not to a folder of the same name.

As far as I’ve been able to research, the recommendation Joe gave me should help me, because it claims to do what I’m looking for, but strangely I haven’t managed to solve my problem.

I’ll probably give up and rename those folders to something else, to avoid this problem, since I’m interested in making progress on my projects.

If it’s ok with you guys, you can close this topic (I’m also a newbie to forums), and if I get around to fixing it later, I’ll contact a moderator to reopen the topic, if that’s possible.

Thanks

Rewrite rules are a work around

[SUBDOMAIN].[DOMAIN]/p/cv

Instead, it redirects me to:

[SUBDOMAIN].[DOMAIN]/p/cv/

This is normal behaviour, I can’t remember if it is Apache that does this or the browser, I think it is Apache. I think if you check network tab in your browser it will show you a location redirect header.

/p/cv = page called cv
/p/cv/ = load index file in this folder
/p/cv/cv.html = load cv.html in /p/cv/

There is a difference between the first 2. The slash makes a real difference.

403 is happening because you do not have a defined index file in /p/cv/.

You might be able to disable the redirect if you really need to, but it will affect the whole server.

Don’t forget you need to define your index files and their load order. You might be able to do this in a htaccess file (it has been a while since I messed with this stuff).

See https://stackoverflow.com/questions/60068645/trailing-slash-vs-no-trailing-slash-no-redirect

DirectorySlash Off

I have not tested this, but maybe what you want is

Options +Indexes

in either a .htaccess file or a particular FILES or DIRECTORY stanza for that directory?

The last path is incorrect, the correct path is:

/p/cv = page called cv
/p/cv/ = load index file in this folder
/p/cv.html = load cv.html in /p/

Because the file “cv.html” and the folder “cv” are both at the same level, inside the “p” folder.

Moreover, the affected pages are not index pages, but just normal web pages. Because at its level there are more web pages. The index.html page is one level above them, and it works fine.

I’ll check out the link you share tomorrow, it looks a bit complicated to read now. Thanks.

  • the names being the same are not your problem
  • it is how you are addressing the folders and the lack of index file.
  • index files need to be defined and they ar enot just index.html