{"id":75,"date":"2009-05-07T09:28:11","date_gmt":"2009-05-07T07:28:11","guid":{"rendered":"http:\/\/luca.lovalvo.net\/1_luca_lo_valvo\/archive\/2188_concerver_les_url_pour_le_rfrencement_migration_suite_au_changement_de_nom_de_domaine.html"},"modified":"2022-11-04T15:57:43","modified_gmt":"2022-11-04T14:57:43","slug":"concerver-les-url-pour-le-referencement-migration-suite-au-changement-de-nom-de-domaine","status":"publish","type":"post","link":"https:\/\/luca.lovalvo.ch\/blog\/concerver-les-url-pour-le-referencement-migration-suite-au-changement-de-nom-de-domaine\/","title":{"rendered":"Concerver les URL pour le r\u00e9f\u00e9rencement (Migration suite au changement de nom de domaine)"},"content":{"rendered":"<p>Petit bout de code, fait vite fait hier soir avec <a href=\"http:\/\/jonasluthi.com\/\" target=\"_blank\" rel=\"noopener\">Jonas<\/a> suite &agrave; la migration de son blog.<br \/>L&#39;objectif &eacute;tait de conserver sur son ancien domaine (host) les URL d&eacute;j&agrave; r&eacute;f&eacute;renc&eacute;es et qu&#39;elles soient redirig&eacute;es sur le nouveau domaine.<\/p>\n<p><strong>1: R&eacute;cup&eacute;ration des URI<\/strong> :<\/p>\n<p>=&gt; Dans un fichier .Htaccess :<\/p>\n<p>&nbsp;&nbsp;&nbsp; <font color=\"#0000ff\">RewriteEngine on <\/font><br \/><font color=\"#339966\">&nbsp;&nbsp;&nbsp; RewriteRule (.*)$ index.php [L]<\/font><\/p>\n<p>La RewriteRule permet de redirger n&#39;importe quelle URI (\/aaa\/bbb\/fichier.html) sur l&#39;index. <\/p>\n<p>&nbsp;<\/p>\n<p><strong>2: Redirection vers le nouveau domaine <\/strong><\/p>\n<p>=&gt; Index.php <\/p>\n<p><font color=\"#0000ff\">&lt;?php<br \/>$r_url=$_SERVER[&#39;REQUEST_URI&#39;];<br \/><font color=\"#808080\">\/\/$r_url=substr($r_url, 5);<\/font><br \/>$New_host=&quot;<font color=\"#339966\">http:\/\/www.votredomaine.ch<\/font>&quot;;<\/p>\n<p>header(&quot;location: $New_host$r_url&quot;);exit;<br \/>?&gt;<\/font><\/p>\n<p><strong>Explication : <\/strong><\/p>\n<p><font color=\"#0000ff\">$r_url=$_SERVER[&#39;REQUEST_URI&#39;];<br \/><\/font> &nbsp;&nbsp;&nbsp; =&gt; Recup&egrave;re l&#39;URI<\/p>\n<p><font color=\"#0000ff\"><font color=\"#808080\">$r_url=substr($r_url, 5);<br \/><\/font><\/font>&nbsp;&nbsp;&nbsp; <font color=\"#0000ff\"><font color=\"#808080\"><font color=\"#993366\">Permet de supprimer les 5 premiers caract&egrave;res.<\/font><\/font><\/font><font color=\"#993366\"><br \/><\/font>&nbsp;&nbsp;&nbsp; <font color=\"#0000ff\"><font color=\"#808080\"><font color=\"#993366\">Sur l&#39;ancien domaine, les URI &eacute;tait sous la forme<br \/><\/font><\/font><\/font>&nbsp;&nbsp;&nbsp; <font color=\"#0000ff\"><font color=\"#808080\"><font color=\"#993366\"><font color=\"#999999\">http:\/\/xxx.domain.tld\/site\/le_blog\/&#8230;<\/font><br \/><\/font><\/font><\/font>&nbsp;&nbsp;&nbsp; <font color=\"#0000ff\"><font color=\"#808080\"><font color=\"#993366\">alors que sur le nouveau domaine :https:\/\/www.domaine.tld\/le_blog\/&#8230;<br \/><\/font><\/font><\/font>&nbsp;&nbsp;&nbsp; <font color=\"#0000ff\"><font color=\"#808080\"><font color=\"#993366\">Il fallait donc supprimer <font color=\"#999999\">\/site.<\/font><\/font><\/font><\/font><\/p>\n<p><font color=\"#0000ff\">$New_host=&quot;<font color=\"#339966\">http:\/\/www.votredomaine.ch<\/font>&quot;;<br \/><\/font> &nbsp;&nbsp;&nbsp; =&gt; Le nouveau domaine <\/p>\n<p><font color=\"#0000ff\">header(&quot;location: $New_host$r_url&quot;);exit;<br \/><\/font>&nbsp;&nbsp;&nbsp; =&gt; On redirige <\/p>\n<p><font color=\"#ff0000\">Attention, cette methode fonctionne &agrave; condition que les URL soient identiques des deux cot&eacute;s (ancien et nouveau domaine). <\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Petit bout de code, fait vite fait hier soir avec Jonas suite &agrave; la migration de son blog.L&#39;objectif &eacute;tait de conserver sur son ancien domaine (host) les URL d&eacute;j&agrave; r&eacute;f&eacute;renc&eacute;es et qu&#39;elles soient redirig&eacute;es sur le nouveau domaine. 1: R&eacute;cup&eacute;ration des URI : =&gt; Dans un fichier .Htaccess : &nbsp;&nbsp;&nbsp; RewriteEngine on &nbsp;&nbsp;&nbsp; RewriteRule (.*)$ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-programmation"],"_links":{"self":[{"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":1,"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"predecessor-version":[{"id":283,"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/posts\/75\/revisions\/283"}],"wp:attachment":[{"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/luca.lovalvo.ch\/blog\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}