Frage

I wanted to set a maintenance page for my website.

To do so, I check a field in the DB, in the first script running (MY_Controller). If it's on maintenance, I would like to redirect the user to the maintenance page. This works :

redirect("maintenance", 'location');

Here is my issue. I want to set the header code to 503 in order to avoid bots indexing the maintenance page in place of the real one. But whenever I do this :

redirect("maintenance", 'location', 503);

The maintenance page doesn't load, the url doesn't change...

Any idea ?

Thanks ahead !

War es hilfreich?

Lösung

I think you can't set the 503 HTTP Status using the redirect() function that CI provides. But you can set the 301 code (temporal redirection), which means that the search engine will know that your page is temporally redirected and it will not index the maintenance page.

More info here: http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html

Andere Tipps

This is an old question, but maybe someone stumbles upon this.

I use the redirect() function from CI to show the maintenance page and tried to use the 503 response code since this feels the correct way for a maintenance page.

I found an answer on stackoverflow which let's you redirect with a 307 code but it still returns code 503 to the browser.

The trick is to set the headers after the content of the maintenance page in the view file. (Not ideal but hey, It returns the 503 code)

<?php
    header('HTTP/1.1 503 Service Temporarily Unavailable');
    header('Status: 503 Service Temporarily Unavailable');
    header('Retry-After: 3600');
?>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top