This site uses third-party cookies, learn more or accept
dark light

Fallback resource overview

Written by Max Pelic on
Update: the Jelly URL link shortener is live, be one of the first people to check it out!
For a limited time, get an exclusive discount by using the coupon code WEBSITE5OFF when you sign up for a free trial.

I started web development on a Mac, and later bought a Windows computer. When I ran a testing server on the Mac, it automatically used the nearest index file if the file you requested didn't exist (at least that's how I thought it worked, but I didn't have much server experience at that point and I could have been totally wrong).

When I installed Apache on my windows computer, I tried to replicate that behavior. But I had no idea what to search for due to my inexperience with servers.

Luckily I stumbled across the solution, and found it really useful when setting up a dynamic site with multiple dynamically generated pages.

Here's an overview of how to set up a fallback resource and some best practices.


You can set up a fallback resource in your httpd.conf file, or you can put it in your .htaccess file. Either way, just add the FallbackResource keyword followed by the path to your default file.

1FallbackResource /path/to/file.php

Some things to note:

Never use a relative path! When you use a relative path, it uses the directory the user specified in the url, not the directory specified, which can lead to an endless loop.

This may seem obvious, but remember if a file exists, the server won't use the fallback resource. So if you want to serve all pages from a fallback resource, don't include any other files in the folder.

It's also helpful to remember that when you have a bunch of dependencies (Javascript and/or CSS) and don't want to have to link them all in the fallback resource. You can still have a folder of them and link to them without worrying about handling them in you fallback file.

Share this article:

Previous Article: Run Apache on Windows without any extra software

Next Article: Free Resources for Web Devs