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:
1 2 3 4 5 |
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] |
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:
1 2 3 |
<?php echo "<iframe width='420' height='315' src='https://www.youtube.com/embed/krK7Q49o6uA' frameborder='0' allowfullscreen></iframe>"; ?> |
Enjoy it!