PHP – Static landing page with .htaccess

Have you ever thought how the web server acts in case that you enter an address, which does not exist? In many sites (including this one), you go to a fancy 404 page. This linking to that special page is done through .htaccess file, which nicely rewrites the address, if it does not exist to a given page.

E.g. like in the example, anything you write, you would be redirected to index.php, where you may see an <iframe> of the “Wherever you go” hit of Status Quo. :


So how do we achieve it?

With a small 6 line “.htaccess” file in the project, containing the following:

And that is quite enough for Apache (or any other web server) to direct you to youtube if you write “lala” or “sadfasdasfs” in the url.

This is the index.php code, in case that you are fans of Status Quo:

Enjoy it!

As always (or almost!) in GitHub!