0

Is there a way I can set a 'fallback' page?

For example, my technique for updating pages on my website is to firstly remove my original index.php and then replace it with a seperate index.html that reads "We'll be back soon!". This is to explain that all pages are down for maintenance (as I upload updated content).

This means anyone attempting to access my home page will be greeted with the maintenance message. The problem, though: if someone manually types in the URL of the page they are trying to access they would instead be resulted with a "Page not found" error.

Is there a way in which I can direct the user to index.html if they are attempting to visit a location that does exist - but just not right now (since I removed it to update content) ...if that makes any sense ;D

  • 1
    just use `.htaccess` and redirect anything to `index.html`?! – eisbehr Jul 23 '18 at 09:15
  • How does one do that? I am using a free Hosting service (and have never actually played around with a server of my own) – The Demon Hunter Jul 23 '18 at 09:16
  • There's no such thing as "does exist but just not right now". Something either exists or it doesn't. – David Jul 23 '18 at 09:17
  • There are thousands of examples for `.htaccess`. Search it by yourself. This question here is obsolete, because this was requested so often. https://stackoverflow.com/questions/18406156/redirect-all-to-index-php-htaccess – eisbehr Jul 23 '18 at 09:18
  • I should probably read up about this .htaccess you speak of - thanks for pointing me in the right direction! – The Demon Hunter Jul 23 '18 at 09:20

1 Answers1

0

Assuming this is an Apache (or compatible) web server, place an .htaccess file in the document root directory (where your index.html usually goes) and put theses lines in it:

RewriteEngine on
RewriteRule ^ maintenance.html

This makes the web server respond to any and all requests with the maintenance.html file. Obviously, put your "under maintenance" web page there. You'd need to tweak that a bit if you wanted to serve images on that maintenance page, but this should get you going. See https://stackoverflow.com/a/20563773/476.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • As an moderator, I would expect you would just add multiple duplicates to the question, instead of a new answer ... – eisbehr Jul 23 '18 at 09:20