Lately i was reading about HTTP and i came across URL Rewriting and URL Canonicalization.
I read that the URL canonicalization error occurs when the same web page is able to be loaded from multiple URLs like:
http://www.example.com/index.php
First of all, who determines that typing http://example.com will automatically redirect to http://www.example.com?Is it a setting in my hosting company's server?
Secondly, does the link rel="canonical" solves the problem? For example inserting the code below inside the head part of the page http://www.example.com/index.php
<link rel="canonical" href="http://www.example.com" />
And if this solves the problem how can i check that this is working correctly? Will i see a change of URL from http://www.example.com/index.php to http://www.example.com ? Because i did it and i didnt see any changes.
Is the 301 redirection through .htaccess file better than rel="canonical" solution?
If i rewrite (through .htaccess) the http://www.example.com/index.php into http://www.example.com , will this be a solution (regarding duplicate contents)? Cause to me, rewriting looks more like a visual change rather than anything else.
Thanks in advance.
First of all, who determines that typing http://example.com will automatically redirect to http://www.example.com?Is it a setting in my hosting company's server?
The hosting company's server or you can create a 301 redirect to direct everything to the canoncical URL.
Secondly, does the link rel="canonical" solves the problem? For example inserting the code below inside the head part of the page http://www.example.com/index.php
It will tell things like indexing bots for search engines that the URL's are the same, It doesn't do anything about redirecting you to the actual canonical URL. Browsers may even choose to cache based on pages who has a different canonical URL.
Doing one or the other, or both, depends on what you want to do. Do you want people to be able to access all the different URLs (use canonical link) or do you want to force all the requests to look the same in the browser's location bar (use 301 redirects). With 301 redirects, indexing bots will also know that one URL is permanently redirected to another, and whatever metadata related to the old should be applied (at some level) to the new URL.