Re: Re-direction without flickering

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
If you have scripting support available, use the HTTP 301 response
code.  This far better for search engines too, because then they will
automatically pick up the new location of the page.

In ASP-VBScript:

' Permanent redirection to
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", " /"


// Permanent redirection to
header("HTTP/1.1 301 Moved Permanently");
header("Location: /");

Re: Re-direction without flickering

Hot off the press:

Redirection with HTTP 301 via PHP, ASP, Javascript, and Meta

Re: Re-direction without flickering

humbads & Andy,

Thanks for your comments. From what I learned, it seems that I'll have to
provide some more details to see which of the suggested methods would be
best for a case like mine. First, I do have PHP scripting available, and
also some PHP knowledge. (And I would like to get along with HTML and PHP as
I have no knowledge about ASP.)

What I'd like to do on the homepage is:

1. Use a PHP function to determine the language of the browser.

2. If the language could be successfully retrieved, automatically forward to
the specific homepage for that language.

3. If the language could not be retrieved, or if I have no specific homepage
for that language, or if the redirection failed due to browser security
settings, a multi-language "default" homepage is displayed, where the user
may select his language himself.

For step 2, I currently use the meta-tag listed in my OP (which results in a
short flickering es the multi-language page is shortly displayed before the
language-specific page appears). As far as I learned from your postings, I
could use PHP to send 301/302 codes instead. I assume if I do this before
the HTML part of the document, the redirection would take place without
displaying the page, so it would not flicker. Right?

However, is it appropriate to use 301/302 codes in this case? After all, I
do not want to indicate that the site has actually moved temporarily or
permanently, but only to forward to a specific sub-page within the same

What do you think?


Re: Re-direction without flickering


Quoted text here. Click to load it


Send a 302

Re: Re-direction without flickering

Yes, send 302 and it won't flicker when you use the Location header.
For public websites, it's good to use the appropriate status code
whenever doing a redirect.  For intranet applications or private
websites, I typically do not bother with sending a status code; I just
do the redirect by itself.

Re: Re-direction without flickering

As far as I googled I can set a 302 redirection by simply setting

header("Location: /");

I tried this and found that it works on my local test server (XAMPP/Apache
on Windows XP), but it does *not* work at my providers' webspace (Strato,
using Apache on Unix).

However, I *can* successfully use a similar call for redirecting to the
*same* page.  I have 2 domains that target the same site, and I use the
following code to make the browser display the name of domain2 also when it
is called with domain1:

if ($_SERVER['SERVER_NAME'] != '')
   header("Location: ");

What could be the reason why the above works perfectly at my providers'
webspace, but I cannot redirect to a different page? I guess its a matter of
configuration as it does work for my local server.


Re: Re-direction without flickering

Gaaaaa... just found the solution: I used the header("Location: ...")
redirection *after* the <html> tag.

Now I no longer wonder why it did not work at the providers' webspace, but
rather wonder why it did for my local server. However, now it runs smoothly
on both servers.

Thank again for all your advice!


Re: Re-direction without flickering

Don't worry, that is a very common mistake. I still make it sometimes
after so many years.

But you bring up a good point, when I use the Location header by itself
in PHP/Apache, I get these headers.

Location:=B7 /

Using Response.Redirect in ASP/IIS results in:

Location:=B7 /

If I use Response.AddHeader "Location" by itself in ASP/IIS, I get:

Location:=B7 /

Something, either the web server or the scripting environment, is
automatically changing the status code when the location header is
specified.  Anyone know what it is? I'm guessing it is the scripting

Location by itself will always redirect.  But I guess to be safe, one
would want to specify the status code where it needs to be explicit,
rather than relying on the scripting environment/web server to
automatically set it.

Site Timeline