Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Google PageSpeed says this:

Avoid landing page redirects

To speed up page load times for visitors of your site, remove as many landing page redirections as possible, and make any required redirections cacheable if possible.

http://xyz.com/ is a cacheable (30 days) redirect to http://www.xyz.com/

I'm using PHP and I defined:

if ($_SERVER['SERVER_NAME']!="localhost") {
define('SITE_URl', "http:// www.abc.com/");
}

.. so please tell me how to do cache-able redirection?

share|improve this question
    
Most redirects will cache automatically without any further intention thanks to DNS caching of browsers. –  bybe Jul 28 '13 at 19:43

2 Answers 2

Using server-side scripting (i.e., PHP) is not the fastest way to do redirects with because first the request is received by the web server, then the PHP code is interpreted, and then the results are sent back to the client.

Instead, you can do the redirect in your web server configuration, bypassing the need to run PHP. For example with Apache, you can use the mod_rewrite module. You can then add caching for requests as covered here: Apache - Caching Guide

Even faster than web server redirects, however, would be to do this at the DNS level using a CNAME (providing that you're forwarding to another host, without a path):

www.old-abc.com IN CNAME www.abc.com.

For the message returned from PageSpeed regarding redirecting xyz.com (without the 'www') to www.xyz.com (with 'www`), you can use either approach above, however using DNS will be faster, reduce the load on your web server, and negate the need for any caching.

share|improve this answer

I believe that when google refers to cacheable redirects they are referring http status '301' redirects (Moved Permanently) vs '302' redirects (Found) or '307' (Temporary).

See details on https status definitions.

So if you were using PHP to do your redirects via the header() function, you'd want to use something like:

header("Location: /foo.php",TRUE,301);
share|improve this answer
    
Google's PageSpeed Service, setup as an intermediary between your server and the browser via DNS as discussed in this question, is advising to make landing page redirects cacheable to speed them up. Whether the redirect is permanent is not a factor. PHP redirects can be made cacheable, however they're relatively very slow as compared to the others covered, and the message is specific to redirecting to the www subdomain, which is best done using DNS so it's cached during lookups. –  dan Aug 4 '13 at 5:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.