Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
Coupe WPB
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Comment déplacer correctement WordPress d’un sous-domaine vers un domaine racine

Note éditoriale : Nous percevons une commission sur les liens des partenaires sur WPBeginner. Les commissions n'affectent pas les opinions ou les évaluations de nos rédacteurs. En savoir plus sur Processus éditorial.

Vous souhaitez déplacer un site WordPress d’un sous-domaine vers le domaine racine ?

Le processus est assez facile à suivre, et il existe également un moyen d’enregistrer votre classement en matière de référencement.

Dans cet article, nous allons vous afficher comment déplacer facilement WordPress d’un sous-domaine vers un domaine racine avec des instructions étape par étape.

Moving a WordPress site from subdomain to root domain

Transférer WordPress d’un sous-domaine à un domaine racine

Un sous-domaine est une extension de votre nom de domaine racine. Par exemple, http://yourwebsite.example.com est un sous-domaine de example.com. Dans ce cas, exemple.com est le domaine racine.

Les moteurs de recherche considèrent le sous-domaine comme un site totalement différent. C’est pourquoi vous devez veiller à rediriger correctement les moteurs de recherche vers le domaine racine après le transfert. Cela vous aidera à préserver votre classement dans les moteurs de recherche après le transfert de votre site.

Contrairement au déplacement d’un site WordPress vers un nouvel hébergeur ou un nouveau nom de domaine, le déplacement d’un site vers le domaine racine est un peu plus facile.

Principalement parce que les deux sont généralement hébergés par la même entreprise d’hébergement web. Cela vous permet de sauter quelques étapes.

Voyons comment déplacer un site WordPress d’un sous-domaine vers le domaine racine.

Étape par étape. Créez une sauvegarde complète de votre site

Vous devriez toujours garder une solution de sauvegarde installée sur votre site pour des sauvegardes automatisées. Il existe de nombreux plugins de sauvegarde WordPress que vous pouvez utiliser pour garder votre contenu WordPress en sécurité.

Si vous avez déjà installé un programme d’extension de sauvegarde, vous vous dites peut-être que vous pouvez sauter cette étape.

Cette étape a pour but de vous rappeler que même si vous avez des sauvegardes automatisées de votre site, vous devez toujours créer une sauvegarde complète de votre site. Cela comprend une sauvegarde de la base de données ainsi qu’une sauvegarde de tous vos fichiers et dossiers WordPress.

Une fois la sauvegarde terminée, veillez à la stocker sur un site distant ou sur votre ordinateur.

Étape par étape. Déplacer vos fichiers WordPress du sous-domaine vers le dossier racine

Tout d’abord, vous devez vous connecter à votre site à l’aide d’un client FTP ou du gestionnaire de fichiers de cPanel. Une fois connecté, rendez-vous à l’emplacement de votre sous-dossier et téléchargez tous vos fichiers WordPress sur votre ordinateur.

Download WordPress files

Ensuite, ouvrez le dossier public_html de votre domaine racine. Selon la façon dont votre environnement d’hébergement WordPress est configuré, ce dossier pourrait également être nommé www ou d’après votre nom de domaine.

Vous devez maintenant téléverser tous les fichiers WordPress que vous avez téléchargés précédemment dans le répertoire racine.

Upload WordPress files to root domain

Étape par étape. Modifier les réglages de l’URL de WordPress et de l’URL du site

Une fois que vous aurez déplacé les fichiers WordPress, vous ne pourrez plus accéder à la zone d’administration de WordPress sur le domaine racine. En essayant de vous connecter au site racine, vous serez renvoyé vers la zone d’administration du site du sous-domaine.

Pour corriger cela, passez au client FTP et allez dans le répertoire racine de votre nom de domaine. Ensuite, vous devez modifier le fichier wp-config.php et ajouter les lignes suivantes juste avant la ligne ‘That’s all, stop editing ! Bon blog ».

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

N’oubliez pas de remplacer exemple.com par votre propre nom de domaine. Si vous souhaitez que votre site racine utilise www, vous devrez saisir les URL avec le préfixe www.

Enregistrez vos modifications et téléversez le fichier wp-config.php sur votre site.

Vous pouvez maintenant visiter la zone d’administration de votre site WordPress sur le nom de domaine racine.

Étape par étape. Mise à jour des URL

Votre site WordPress a été déplacé vers le domaine racine, mais il y aura des liens à l’intérieur de votre base de données WordPress pointant vers le sous-domaine.

Corrigeons cela.

Vous devez installer et activer l’extension Go En direct Update URLs. Pour plus de détails, consultez notre guide étape par étape sur l’installation d’une extension WordPress.

Une fois activé, vous devez vous rendre sur la page Outils  » En direct  » à partir de votre panneau d’administration WordPress.

Select core tables to update

En haut de la page, vous pouvez choisir de mettre à jour les URL de vos publications, commentaires, options, données utilisateur, termes et autres domaines en cochant la case correspondante.

Ensuite, défilez jusqu’au bas de la page. Ici, vous devez saisir l’URL de votre sous-domaine à côté de l’option « Ancienne URL » et ajouter votre domaine racine en tant que « Nouvelle URL ».

Enter old and new URL

Une fois que vous avez terminé, cliquez sur le bouton « Mettre à jour les URL » pour continuer.

L’extension va maintenant mettre à jour toutes les URL dans votre base de données WordPress.

Étape par étape. Rediriger tout le trafic des sous-domaines vers le domaine racine

Maintenant que vous avez déplacé les fichiers WordPress, assurons-nous que le trafic de votre sous-domaine est redirigé vers le nom de domaine racine.

Allez dans le dossier de votre sous-domaine et assurez-vous que les fichiers masqués sont forcés d’être visibles.

Les Réglages de votre client FTP disposent d’une option permettant de toujours afficher les fichiers masqués. Dans FileZilla, elle se trouve sous l’option Serveur  » Forcer à afficher les fichiers masqués.

Show hidden files

Si vous utilisez le gestionnaire de fichiers cPanel, cliquez sur le bouton « Réglages » dans le coin supérieur droit de l’écran. La fenêtre surgissante des préférences s’affichera. Vous devez sélectionner « Afficher les fichiers masqués », puis cliquer sur le bouton « Enregistrer ».

Show hidden files in cPanel file manager

Si votre dossier de sous-domaine possède déjà un fichier .htaccess, vous pouvez le supprimer et en créer un nouveau. Dans le nouveau fichier .htaccess, vous devez copier et coller le code suivant :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yoursubdomain\.example\.com$ [NC]
RewriteRule ^(.*)$ "http://example.com/$1" [R=301,L]
</IfModule>

N’oubliez pas de remplacer votre sous-domaine par votre sous-domaine réel, et exemple.com par votre nom de domaine.

Veuillez noter que la ligne RewriteRule utilise une URL qui n’est pas www. Si vous souhaitez utiliser www dans votre domaine racine, vous devrez alors ajouter votre URL avec un préfixe www.

Enregistrez vos modifications et téléversez votre fichier .htaccess sur le serveur.

C’est tout. Vous avez bien déplacé votre site du sous-domaine vers le domaine racine. Vous pouvez maintenant visiter votre site pour le voir en action. Testez votre site pour vous assurer que tout fonctionne correctement.

Nous espérons que cet article vous a aidé à déplacer votre site du sous-domaine au domaine racine. Vous pouvez également consulter notre guide ultime de référencement WordPress pour les débutants, ainsi que nos choix des meilleures extensions de redirection 404 pour WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Divulgation : Notre contenu est soutenu par les lecteurs. Cela signifie que si vous cliquez sur certains de nos liens, nous pouvons gagner une commission. Consultez comment WPBeginner est financé, pourquoi cela compte et comment vous pouvez nous soutenir. Voici notre processus éditorial.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

L'ultime WordPress Toolkit

Accédez GRATUITEMENT à notre boîte à outils - une collection de produits et de ressources liés à WordPress que tous les professionnels devraient avoir !

Reader Interactions

63 commentairesLaisser une réponse

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Heidary says

    hello and thank you for this article
    i moved a website from subdomain to domain but the problem that i have is when i enter the subdomain url in the browser the website is being displayed but the url that is being displayed in the address bar is the subdomain , and when i click one of the links on the website then i am being redirected to main domain , please note there is nothing on the subdomain right now.
    i do have 301 redirect on the subdomain but something doesn’t seem to be working properly , any idea what could be causing this? any help or tip would be appreciated
    thank you in advance

    • WPBeginner Support says

      If you’ve already done the step to update your URLs, we would recommend checking your Settings>general page to ensure the URL was updated correctly there.

      Administrateur

  3. Jesse Dill says

    I am going through the steps and on step 3, I followed the php syntax but it caused some errors and I couldn’t get to any of the wordpress admin sites. I had to remove the pre tags and just use:

    define(‘WP_HOME’,’http://example.com’);
    define(‘WP_SITEURL’,’http://example.com’);

    After that it worked. Just in case anyone comes across the same issue as me.

  4. sarah says

    Hi, Step two doesn’t seem to work for me as CPanel won’t let me download the directory sub.example.com

    I can download individual files but not folders or directories. I have tried compressing to .zip but the .zip file is empty.

    Can you please advise? Many thanks

  5. Jessica says

    I see that Velvet Blues Update URLs plugin on wordpress.org is noted « This plugin hasn’t been tested with the latest 3 major releases of WordPress. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress. »

    Do you recommend a different plugin now or to still use this one?

  6. Caleb Byers says

    Do you need to update anything in the databases after doing the steps in the article? Whenever moving a site I’ve seen people say that there are a few steps in the databases, but not in this article… Is there a reason why?
    Thanks.

  7. Del Abernethy says

    Worked a charm up until I tried to login to wp-admin. The site already had files (which I over-wrote) and users but now it won’t recognise the existing users. It does allow me to login using the username & password from the sub-domain so I’m assuming it is linked to the sub-domain database. Is it possible to link it to the existing original database?

    • WPBeginner Support says

      You would want to check the wp-config file for the database it is connected to for your site and you would be able to change that in your file. That would normally happen if you didn’t overwrite the existing file if you were trying to replace a site with the one on the subdomain.

      Administrateur

    • WPBeginner Support says

      It would depend on what references you are talking about. If you mean links in the articles then the velvet blues plugin updates those.

      Administrateur

    • WPBeginner Support says

      You would likely want to check with your hosting provider to ensure they don’t have a firewall and your SSL certificate is active as the most common reasons

      Administrateur

  8. Ben says

    Hey – do you reccomend also using Googles change of address tool, to tell it subdomain.primarydomain.com is now primarydomain.com ?

    thanks

    • WPBeginner Support says

      If you want you can also use that tool, the redirects would normally resolve this for you.

      Administrateur

  9. Sara says

    Hi,
    I followed your steps up until the end of step 3, where I have edited the wp-config.php file
    I then go to the wp-admin. I enter my details and it just goes back to the same login. It’s not allowing me to login to the wordpress backend.
    It’s like it’s redirecting me.
    Are you able to help?
    I’d really appreciate it.
    Thanks,
    Sara

  10. Sofia says

    Hello, I did everything and it worked! But now I’m wondering, how do I keep my subdomain as a « staging » website, so that I can change things and not affect the one on the domain. I’d have to make a new database (using a backup) right?
    How to assure I don’t do anything wrong?

  11. Oliver says

    In my subdomain folder, I have 2 .htaccess files. One is in subdomains/example, the other is in subdomains/example/web. The latter is next to all the other wordpress files. Which one should I delete and replace with the code in step 5?

    • WPBeginner Support says

      You may need to check with your host but from the sound of it, you would modify the second one.

      Administrateur

  12. Aldo Salim says

    Hi, thank you so much for the great help.

    However, i do not want to keep the old sub-directory folder. Will it be okay to delete the sub-directory folder?

  13. Joshua Orizu says

    I am building a websites and the domain name is displaying site.comp50 instead of site.com how do i fix this

    • WPBeginner Support says

      You may want to check with your hosting provider to ensure the correct domain is attached to where your site is and then you would be able to update the url in your Settings>General area

      Administrateur

  14. Jeremy says

    What happens to the blog posts on the root domain during a migration?

    I currently built a redesigned site on a subdomain, Sandbox.WebsiteName.com, and want to migrate it over to the the root domain. However, I want to keep the blog posts.

    i’m worried about the seo. Do the blog post from the root domain get overwritten? If not how would i access them to redirect them?

    Thanks,

  15. Madison says

    Hi,

    Would this method work if I wanted to move a subdomain, which a friend uses, ie, xxx.example.com, over to their new account so it can be its own website like xxx.com?

    If not, is there anything that would work at all or would they just have to start over, thus losing all the comments, page views, etc?

  16. Rui says

    Hi,
    This tutorial is great, but didn’t work for me. I don’t know why.

    I can access to admin area, in homepage the images are not shown and when i tried to access posts and products says « Not Found
    The requested URL /shop/index.php was not found on this server. »

    I would like some help if possible.
    Thank you a lot

    • WPBeginner Support says

      You may want to ensure steps 3 and 4 were completed for the most common reason for that.

      Administrateur

    • Canonical Bear says

      Hi,
      We had the same problem (my team and I). Only the Home Page would open, and all other pages were broken.
      You need to update the permalinks. Go to Dashboard ->Settings -> Permalinks. Here, don’t make any changes, just click on « Save Changes ».
      It re-apply settings with the current directory as root.
      All the best.

  17. Milan says

    Hello WP Team,

    just one quick question… what is the difference between this procedure and clone website from cpanel installatron (godaddy). Can I use clone for same purpose? Do I need to made some additional changes after cloning. It’s looks much easier to do this with clone option.

    Thanks for good work!

  18. Melind says

    This worked like a charm! The part that takes the longest is uploading and downloading the files. Thank you!

  19. smv says

    This didn’t work for me at all. Step 4, using the Velvet Blues plug-in to update the URLs, didn’t update most of them. There were still loads of references to the old site. I had to re-do everything, but I used the duplicator plug-in, which worked well.

  20. Gábor Sztárcsevics says

    Hi!

    Is this modification will change the records in the database, which is used for my wordpress on the subdomain.example.com?

    Shouldn’t I create a new database for the migrated wordpress?

    Thank you!

    • WPBeginner Support says

      Hi Gábor Sztárcsevics,

      Since you are moving from subdomain to root domain on the same hosting environment, your old database would work just fine after you update URLs as shown in the tutorial.

      However, if you would like to create a new database, then you can do that as well. You will then need to export your data from the old database to the new one and update URLs.

      Administrateur

  21. Shravan says

    RewriteCond %{HTTP_HOST} ^yoursubdomain\.example\.com$

    in this code, do i need to remove those 2 backward slash’s

  22. Denise says

    I don’t see where you remove the old wordpress files. Are they automatically replaced when you upload the subdomain files to the root?
    Thank you.

  23. Charlotte Jones says

    I tried this and got a HTTP 500 error. Luckily I backed everything up, but I don’t understand. All the files are there in public_html and I changed the wp-config file to point to the root domain.

  24. Jon says

    Very good thank you. Went like a dream apart from an error I made by amending the old subdomain .htaccess file instead of the new one in the root. Your advice was excellent tho.

  25. Juan F. says

    Hi guys,

    After doing all the steps, if I want to save a page I get an error and automatically redirects me to the post list, could you help me please?

    Thanks in advance.

    • Anita says

      Hello!
      If I make the site in the exemple.com/Wordpress folder, do I have to move it to the example.com folder or can I just redirect it, how does that work?
      /Anita

  26. Ousman Faal says

    This was definitely useful. I was just about to change a demo site on a sub domain to a root domain.
    You guys are live savers.

Laisser une réponse

Merci d'avoir choisi de laisser un commentaire. Veuillez garder à l'esprit que tous les commentaires sont modérés selon notre politique de commentaires, et votre adresse e-mail ne sera PAS publiée. Veuillez NE PAS utiliser de mots-clés dans le champ du nom. Ayons une conversation personnelle et significative.