Mobile app version of vmapp.org
Login or Join
Kristi941

: How can I make redirections cacheable to speed up load times? Google PageSpeed says this: Avoid landing page redirects To speed up page load times for visitors of your site, remove

@Kristi941

Posted in: #Cache #LandingPage #PageSpeed #Redirects

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.

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

I'm using PHP and I defined:

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


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

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Kristi941

2 Comments

Sorted by latest first Latest Oldest Best

 

@Murphy175

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);

10% popularity Vote Up Vote Down


 

@Nimeshi995

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):
old-abc.com IN CNAME abc.com.

For the message returned from PageSpeed regarding redirecting xyz.com (without the 'www') to 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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme