a little problem that's itchying me for the last months. First the good news: with the help of a massiv SO community I was able to rewrite my ugly urls into nice ones: e.g. website.com/page.ast?ln=nl
into website.com/nl/page
But
Google shows the ugly urls in thei开发者_开发技巧r search:
website.com/nl/page.ast?ln=fa
My site page's code do have the canonical settings:
<link rel="canonical" href="http://website.com/nl/page">
<meta name="original-source" content="http://website.com/nl/page"/>
However the results apparently still get indexed under the wrong, ugly urls!
Q1. Why does google ignore the canonical more beautiful link?Perhaps its then best to do this the mechanical way: redirect those website.com/nl/webpage.ext?ln=yy
to website.com/nl/webpage
essentially removing the unnessecary part which doesnt do anything .XXX?ln=YYYY
(where XXX is a 2 or 3 char extension and YYY is the language (can be nl
, be
, fr
but also zh-CN
etc)
EXAMPLE OF UGLY OLD FILES THEIR NICE BEAUTIFIED URLS
/en/somepage.ast?ln=fr /en/somepage
/fr/home.php?ln=zh-CN /fr/home
/xx/zzzzzz.ext?ln=yyyy /xx/zzzzzzz
/xx/zzzzzz?ln=yyyy /xx/zzzzzzz
/xx/zzzzzz.ext /xx/zzzzzzz
Q2. How to rewrite all ugly files to nice urls at once? Sofar, a preliminary design
RewriteRule /XX/ZZZZ(.*anything after and including the dot) /XX/ZZZZ [R=301]
So, what do you recommend? I see suggestions as possible answers. Many thanks in advance!
Canonical url say that, main url representing this content is different. Its still a different URL for google, It will give some weight to canonical url but may not remove old url and prevent you from duplicate content considerations. Its used specially when you have urls to which add some query parameter related to content.
http://something.com/1234/234?ref=g1
andhttp://something.com/1234/234?ref=widardnb
are same url for you but google will consider it as different url, now in this case you give canonical urlhttp://something.com/1234/234
. This you since you can't control the what people like affiliate may append to your url.If you want actually to show only beautified url to users permanently. Then you have to do 301 redirect.
To do this use mod_rewrite in apache config file.
LoadModule rewrite_module /path/to/modules/dir/mod_rewrite.so
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ~ !^$ [OR] #Query string is not empty
RewriteCond %{REQUEST_URI} ~ ^(.*)\.(.*)$ #Your url path have . in between
RewriteRule .* %1 [R=301,L] #then redirect to path without extension (else all are handled as it is).
Also enable rewrite log
RewriteLog "/path/to/log/directory/rewrite.log" #change the directory name
RewriteLogLevel 9 #this will help you understanding whats happening behind (disable this once everything starts working)
I have not tested it, but let me know in case of any error.
精彩评论