For a website, I want using URL rewriting to allow easy access to pages and better indexation.
For instance, assume the page about Mozart is:
www.site.ext/composers/index.php?cmd=composers&id=123
Instead of this, I would like that the visitors enter:
www.site.ext/Mozart
and reach the same page.
I also want that robots from search engines index the "friendly" address and be unaware of the "unfriendly" real address.
Both .htaccess
files below work and give access to the same content.
In the browser, the first one keeps the friendly url in the address bar (i.e. www.site.ext/Mozart
),
#Options +FollowSymlinks
RewriteEngine On
RewriteBase /
#AllowOverride all
RewriteCond %{HTTP_HOST} .
RewriteRule ^Mozart$ composers/index.php?cmd=composers&id=123 [L]
whilst the second, with the additional R=301
option, makes a permanent redirection to the "unfriendly" address:
#Options +FollowSymlinks
RewriteEngine On
RewriteBase /
#AllowOverride all
RewriteCond %{HTTP_HOST} .
RewriteRule ^Mozart$ composers/index.php?cmd=composers&id=123 [R=301,L]
As the category names will never change over time, I assume that the first case --URL rewriting only without perceivable redirection-- is better in this situation as search engines would store and display the friendly url instead of the unfriendly one. Is this indeed the case?
Concerning the internal links accross the site (i.e. anchors in pages), I assume that I should use PHP (or equivalent) to dynamically write their friendly URL version instead of the default unfriendly one, so that search engines won't index unfriendly URL.
As a complement, to avoid indexation of duplicate URLs (in case of omissions in the code), I assume it would be wise to mention in each page its friendly URL as canonical link:
<head>
...
<link rel="canonical" href="http://www.site.ext/Mozart" />
...
</head>
Are above assumptions correct or are there contraindications?