1

URL canonization is an important aspect in SEO, now I have a website hosted on Yahoo my small business which doesn't allow for .htaccess to be uploaded, now in such a case how do I keep my domain consistent.

HERE is a Chris coyer script i came across, it shows how to make the URL, consistent using the .htaccess file. but now obviously I can't use the .htaccess file , so how to I make my URL consistent when my host doesn't allow me to upload a .htaccess file?

Simon Hayter
  • 32,999
  • 7
  • 59
  • 119

1 Answers1

4

You could make a very simple test to see if there is www in the URL, and if it hasn't, go to the www version via a 301 permanently moved header:

if( substr($_SERVER['HTTP_HOST'],0,4)!='www.'){
    header('Location: http://www.'$_SERVER['HTTP_HOST'].'/'.$_SERVER['REQUEST_URI'], true, 301);
}

Don't forget to set your canonical tags to www so bots know your preferred URL.

Martijn
  • 6,806
  • 17
  • 36
  • 1
    There's a similar answer here: http://stackoverflow.com/a/7228702/3913970 Note that Martijn's answer won't work as HOST_NAME isn't defined in the $_SERVER array and there's a concatenation operator missing. – user3913970 Jun 04 '15 at 12:23
  • 2
    The URL used in the Location header should be absolute, starting with a scheme ie. http://www.... – MrWhite Jun 04 '15 at 13:17
  • A canonical tag isn't really necessary if the Location header is used because you're doing a redirect and only the target page will return the document. Also, if you use the location header, you should also include this HTTP header: HTTP/1.1 301 Moved Permanently. – Mike -- No longer here Jun 04 '15 at 17:25
  • The canonical should be one of the things you just do. It saves you work in the long run (in my experience). The header has a 301 value, if you scroll to the right a bit you can see it :) – Martijn Jun 05 '15 at 07:17