Posted By

thewickedchemist on 12/16/11


Tagged

redirect add www 301 seo


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ashloren
truespire


SEO - 301 Cononical Redirect - Adds WWW


 / Published in: PHP
 

Issues a check to see if the "www" is included, if not, forces "www" to be appended to the URL in question.

  1. <?php
  2. if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {
  3. header('HTTP/1.1 301 Moved Permanently');
  4. header('Location: http://www.'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  5. }
  6. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: keithbluhm on January 26, 2012

if ( 0 !== stripos( $SERVER['HTTPHOST'], 'www.' ) ) { header( 'HTTP/1.1 301 Moved Permanently' ); header( 'Location: http://www.' . $SERVER['HTTPHOST'] . $SERVER['REQUESTURI'] ); exit; }

Posted By: keithbluhm on January 26, 2012

Whoops: if ( 0 !== stripos( $_SERVER['HTTP_HOST'], 'www.' ) ) { header( 'HTTP/1.1 301 Moved Permanently' ); header( 'Location: http://www.' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); exit; }

You need to login to post a comment.