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?

4
  • 2
    Simple fix would be to use canonical, this would inform Google the master pages, this would do the trick without redirecting pages, however this doesn't solve the issue of you using a host that doesn't support things it should. Jun 4, 2015 at 8:08
  • 2
    What scripting languages can you use?
    – MrWhite
    Jun 4, 2015 at 8:16
  • @w3d , PHP is my prefered scripting language ! Jun 4, 2015 at 11:03
  • @bybe , i get the following url in the browser www.example.co.in so for t he canonical link sould i use <link rel="canonical" href="www.ferroli.co.in" /> ? sorry first time doing this :P Jun 5, 2015 at 10:35

1 Answer 1

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.

4
  • 1
    There's a similar answer here: 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. Jun 4, 2015 at 12:23
  • 2
    The URL used in the Location header should be absolute, starting with a scheme ie. http://www....
    – MrWhite
    Jun 4, 2015 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. Jun 4, 2015 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 5, 2015 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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