I'm on 14.04 about to move up to 18.04. In that version of Ubuntu can I have a folder and a file in the same location with the same name?
My use case is that I have html files without the .html extension, that I push up to AWS S3, where I serve a few websites. Leaving off the .html extension enables me to have clean urls for the websites. And S3 is perfectly happy to have directories and files with the same name, and thankfully they serve the html file rather than a folder if you navigate to the URL that is a file and a folder.
This would be a nice to have in Ubuntu. I could have an html file called 'articles' and a folder called articles, and then my URLs would be "RESTful."
example.com/articles/title
would give you the article with that title, and example.com/articles
would serve up a list of articles.
Anyhow, AWS already does this, I was just hoping Nautilus, or Ubuntu could handle this so I don't have to go through an awkward coding nightmare where my local directories have different names from my server directories.
Does this work in 18.04 or can anyone think of a good work-around?
The OS and file system do not allow this
Ubuntu and its file systems (ext3, ext4, etc.) doesn't allow an identically named file and folder in the same directory.
Therefore,
nautilus
does not allow renaming a folder to an existing file name.However, Ubuntu (GNU/Linux in general) file systems are case sensitive. You can have a folder called Articles and a file called articles in the same location. Note the folder name starts with a capital
A
, while the file name starts with a smalla
.You can use any CaPiTaLiZaTion conventions you want for your folders and files.
An alternative
An alternative is to create a file called
index.html
inside each folder where you want the folder and the file to have the same name. Naming your HTML fileindex.html
and putting them in a folder called e.g.example.com/articles/title
, so the full path isexample.com/articles/title/index.html
, will also accomplish what you're asking.When one types
https://example.com/articles/title
the web server will serve theindex.html
page and browsers won't show theindex.html
. It will show onlyhttps://example.com/articles/title
.Similarly, you can have a file called
https://example.com/article/index.html
to show what you want when one typeshttps://example.com/article
.Thanks to Harry for the alternative and some other points.
Question is a possible duplicate of https://stackoverflow.com/questions/34550299/aws-s3-hosting-url-rewrite. If you look in the comments, you'll even see that his precise use case is removing the .html from his URLs.
While the accepted answer provides a valid, working solution, I think this is a case of the XY problem. In this case, what you really need is a URL Rewriting system, which dispenses with the naming convention problem altogether. While the previous article does not apply to AWS S3, it explains the concept fairly well. Unfortunately, since S3 is not a web server per se, it doesn't have URL Rewrite functionality, but it does have Webpage Redirects which, as stated in the duplicate question's answer, might be able to do this.