apache - How to rewrite 301 the old ugly urls to the new beautified working urls? -
a little problem that's itchying me last months. first news: of massiv community able rewrite ugly urls nice ones: e.g. website.com/page.ast?ln=nl
website.com/nl/page
but
google shows ugly urls in search:
website.com/nl/page.ast?ln=fa
my site page's code have canonical settings:
<link rel="canonical" href="http://website.com/nl/page"> <meta name="original-source" content="http://website.com/nl/page"/>
however results apparently still indexed under wrong, ugly urls!
q1. why google ignore canonical more beautiful link?
perhaps best mechanical way: redirect website.com/nl/webpage.ext?ln=yy
website.com/nl/webpage
removing unnessecary part doesnt .xxx?ln=yyyy
(where xxx 2 or 3 char extension , yyy language (can nl
, be
, fr
zh-cn
etc)
example of ugly old files 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 rewrite ugly files nice urls @ once? sofar, preliminary design
rewriterule /xx/zzzz(.*anything after , including dot) /xx/zzzz [r=301]
so, recommend? see suggestions possible answers. many in advance!
canonical url that, main url representing content different. still different url google, give weight canonical url may not remove old url , prevent duplicate content considerations. used specially when have urls add query parameter related content.
http://something.com/1234/234?ref=g1
,http://something.com/1234/234?ref=widardnb
same url google consider different url, in case give canonical urlhttp://something.com/1234/234
. since can't control people affiliate may append url.if want show beautified url users permanently. have 301 redirect.
to 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 not empty rewritecond %{request_uri} ~ ^(.*)\.(.*)$ #your url path have . in between rewriterule .* %1 [r=301,l] #then redirect path without extension (else handled is).
also enable rewrite log
rewritelog "/path/to/log/directory/rewrite.log" #change directory name rewriteloglevel 9 #this understanding whats happening behind (disable once starts working)
i have not tested it, let me know in case of error.
Comments
Post a Comment