index.html won't open automatically

Viewed 64

We had an assignment to make a website for our Web Design class. I was making it on my Raspberry Pi Apache webserver because of convenience.

I made all links that point to another page like this:

<a href="./folder/">Link to another page</a>

On Raspberry Pi it automatically loads index.html or index.php from that folder and it works perfectly fine. But after downloading everything on the USB drive, I realized that those links won't load.

Microsoft Edge won't load those link at all, and Chrome/Firefox opens "Index of file:///" and lists all files in the directory.

I already made about a hundred of files with thousands of links like those.

The working website that I made can be accessed from anywhere, so I could technically just give the link to the professor, but he wants everything on a USB drive.

So, is there any way to make the browser on his PC load index.html files automatically or I have to change every link from ./folder/ to ./folder/index.html ?

And is there a way to do this automatically or I have to manually find and replace every link?

1 Answers

Unfortunately I think you're going to have to rename all of those links.

Fortunately most modern code editors support regular expression find & replace. I'll use Visual Studio Code as an example. Shift + Ctrl + F pulls up the global (project-wide) search. There's a little button .* to toggle a regular expression search.

Assuming all of your links look like the example you showed you can put this in the search box:

href="\./(.+)/"

And this in the replace box:

href="./$1/index.html"

Here's what you started with:<a href="./folder/">

And Here's the end result: <a href="./folder/index.html">

I'd highly recommend reviewing the items found by this regex selector before you do a global replace. And as always make a backup of your project, or take some other precautions, because this selector might also find links in your project that you don't want changed.

Related