Posted By

thewickedchemist on 12/16/11


Tagged

redirect remove www 301 seo


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

truespire


SEO - 301 Cononical Redirect - Removes WWW


 / Published in: PHP
 

Removes WWW from the current URL, if exists.

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

Report this snippet  

Comments

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

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

You need to login to post a comment.