Deseja mover um site WordPress do subdomínio para o domínio raiz?
O processo é bastante fácil de seguir, e há uma maneira de salvar suas classificações de SEO também.
Neste artigo, mostraremos a você como mover facilmente o WordPress do subdomínio para o domínio raiz com instruções passo a passo.
Transferência do WordPress do subdomínio para o domínio raiz
Um subdomínio é uma extensão de seu nome de domínio raiz. Por exemplo, http://yourwebsite.example.com é um subdomínio de example.com. Nesse caso, example.com é o domínio raiz.
Os mecanismos de pesquisa consideram o subdomínio como um site totalmente diferente. É por isso que você precisa se certificar de redirecionar adequadamente os mecanismos de pesquisa para o domínio raiz após a transferência. Isso o ajudará a preservar as classificações de pesquisa depois de mover seu website.
Ao contrário de mover um site WordPress para um novo host ou um novo nome de domínio, mover um site para o domínio raiz é um pouco mais fácil.
Principalmente porque ambos costumam ser hospedados na mesma empresa de hospedagem na Web. Isso permite que você pule algumas etapas.
Vamos dar uma olhada em como mover um site WordPress do subdomínio para o domínio raiz.
Etapa 1. Crie um backup completo de seu site
Você deve sempre manter uma solução de backup instalada em seu site para fazer backups automatizados. Há vários plug-ins de backup do WordPress que você pode usar para manter seu conteúdo seguro.
Agora, se você já tiver um plug-in de backup instalado, talvez esteja pensando que pode pular esta etapa.
Esta etapa serve para lembrá-lo de que, mesmo que você tenha backups automatizados do seu site, ainda é necessário criar um backup completo do site. Isso inclui um backup do banco de dados, bem como um backup de todos os seus arquivos e pastas do WordPress.
Depois de criar um backup completo, certifique-se de armazená-lo em um local remoto ou em seu computador.
Etapa 2. Como mover seus arquivos do WordPress do subdomínio para a pasta raiz
Primeiro, você precisa se conectar ao seu site usando um cliente FTP ou o gerenciador de arquivos do cPanel. Depois de conectado, vá para o local da subpasta e baixe todos os arquivos do WordPress para o computador.
Em seguida, abra a pasta public_html de seu domínio raiz. Dependendo de como seu ambiente de hospedagem do WordPress está configurado, essa pasta também pode ser chamada de www ou do nome de seu domínio.
Agora, você precisa fazer upload de todos os arquivos do WordPress baixados anteriormente para o diretório raiz.
Etapa 3. Alterar as configurações de URL do WordPress e URL do site
Depois de mover os arquivos do WordPress, você não poderá acessar a área de administração do WordPress no domínio raiz. Ao tentar fazer login no site raiz, você será redirecionado para a área de administração do site do subdomínio.
Para corrigir isso, mude para o cliente FTP e vá para o diretório raiz de seu nome de domínio. Em seguida, você precisa editar o arquivo wp-config.php e adicionar as seguintes linhas logo antes da linha “That’s all, stop editing! Happy blogging”.
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
Não se esqueça de substituir example.com por seu próprio nome de domínio. Se quiser que o site raiz use www, será necessário inserir os URLs com o prefixo www.
Salve as alterações e carregue o arquivo wp-config.php de volta em seu site.
Agora você pode acessar a área de administração do seu site WordPress no nome de domínio raiz.
Etapa 4. Atualizar URLs
Seu site do WordPress foi movido para o domínio raiz, mas haverá links no banco de dados do WordPress apontando para o subdomínio.
Vamos corrigir isso.
Você precisará instalar e ativar o plug-in Search & Replace Everything. Para obter mais detalhes, consulte nosso guia passo a passo sobre como instalar um plug-in do WordPress.
Após a ativação, você precisa acessar a página Tools ” WP Search & Replace no painel de administração do WordPress.
Na parte superior da página, você precisa inserir o URL do subdomínio ao lado do campo “Search for” (Pesquisar por) e adicionar seu domínio raiz no campo “Replace with” (Substituir por).
Ao rolar a página para baixo, você pode optar por atualizar URLs em tabelas específicas do banco de dados do WordPress, como posts, comentários, opções, dados do usuário, termos e outras áreas. Ou você pode selecionar todas as tabelas.
Em seguida, clique no botão “Preview Search & Replace” (Visualizar pesquisa e substituição).
O plug-in mostrará uma visualização de todas as alterações que serão feitas.
Se tudo estiver correto, clique no botão “Replace All” (Substituir tudo) para continuar.
O plug-in agora atualizará todos os URLs em seu banco de dados do WordPress.
Etapa 5. Redirecionar todo o tráfego do subdomínio para o domínio raiz
Agora que você moveu os arquivos do WordPress, vamos garantir que o tráfego do subdomínio seja redirecionado para o nome de domínio raiz.
Vá para a pasta do subdomínio e verifique se os arquivos ocultos são forçados a ficar visíveis.
As configurações de seu cliente FTP têm uma opção para sempre mostrar arquivos ocultos. No FileZilla, ela está localizada na opção Servidor ” Forçar a exibição de arquivos oc ultos.
Se estiver usando o cPanel File Manager, clique no botão “Settings” (Configurações) no canto superior direito da tela. Isso abrirá a janela pop-up de preferências. Você precisa selecionar “Show hidden files” (Mostrar arquivos ocultos) e clicar no botão “Save” (Salvar).
Se a pasta do subdomínio já tiver um arquivo .htaccess, você poderá excluí-lo e criar um novo. Dentro do novo arquivo .htaccess, você precisa copiar e colar o seguinte código:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yoursubdomain\.example\.com$ [NC]
RewriteRule ^(.*)$ "http://example.com/$1" [R=301,L]
</IfModule>
Não se esqueça de substituir seu subdomínio pelo subdomínio real e example.com pelo nome de seu domínio.
Observe que a linha RewriteRule usa um URL não www. Se quiser usar www em seu domínio raiz, será necessário adicionar o URL com um prefixo www.
Salve as alterações e carregue o arquivo .htaccess no servidor.
Isso é tudo. Você conseguiu mover seu site do subdomínio para o domínio raiz. Agora você pode visitar seu site para vê-lo em ação. Teste seu site para ter certeza de que tudo está funcionando bem.
Esperamos que este artigo tenha ajudado você a mover seu site do subdomínio para o domínio raiz. Talvez você também queira ver nosso guia definitivo de SEO para WordPress para iniciantes, bem como nossas escolhas dos melhores plug-ins de redirecionamento 404 para WordPress.
Se você gostou deste artigo, inscreva-se em nosso canal do YouTube para receber tutoriais em vídeo sobre o WordPress. Você também pode nos encontrar no Twitter e no Facebook.
Syed Balkhi
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!
Anna
I’m moving from a subdomain to a new domain – can I follow this guide to do this?
jpettett
If it’s on the same server, than most likely yes. Some of the details may depend on how your hosting is set up and if the different files for each domain are all under the same account.
If the account doesn’t offer a way to move the files directly, you may want to check out this guide: https://www.wpbeginner.com/wp-tutorials/how-to-properly-move-wordpress-to-a-new-domain-without-losing-seo/
Heidary
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
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.
Administrador
Jesse Dill
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.
WPBeginner Support
Thank you for sharing that in case someone else runs into that issue!
Administrador
Valeri Andreev
Thank you so much
sarah
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
WPBeginner Support
You may need to check with your hosting provider to ensure they do not have something on their end that is limiting the download from the cPanel side. To get around that, we would recommend using an FTP program that would not run into that issue. You can see our guide on FTP programs here:
https://www.wpbeginner.com/beginners-guide/how-to-use-ftp-to-upload-files-to-wordpress-for-beginners/
Administrador
Jessica
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?
Caleb Byers
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.
WPBeginner Support
Step 4 handles that
Administrador
Del Abernethy
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
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.
Administrador
Peter Harrison
Does this method update all the references in the database too?
Regards
Pete
WPBeginner Support
It would depend on what references you are talking about. If you mean links in the articles then the velvet blues plugin updates those.
Administrador
Mucha
please advise on the steps for the htaccess. if my subdomain is /new what should it be on the new htaccess?
WPBeginner Support
You would want to take a look at step 5 in the article for that information.
Administrador
Kat
I get a Web Application Firewall error whenever I implement phase 4. What could be the problem?
WPBeginner Support
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
Administrador
Ben
Hey – do you reccomend also using Googles change of address tool, to tell it subdomain.primarydomain.com is now primarydomain.com ?
thanks
WPBeginner Support
If you want you can also use that tool, the redirects would normally resolve this for you.
Administrador
Sunita
Thanku so much… it wouldn’t be possible without your help… thank you again!
WPBeginner Support
You’re welcome
Administrador
Sara
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
WPBeginner Support
There are a few reasons for that, you may want to take a look at our guide below for some possible solutions:
https://www.wpbeginner.com/wp-tutorials/how-to-fix-wordpress-login-page-refreshing-and-redirecting-issue/
Administrador
Ghassen GaraAli
Hello,
Does this work to move a subdirectory to root ?
thank you
WPBeginner Support
Yes, you can follow our guide for that as well.
Administrador
Sofia
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?
WPBeginner Support
For setting up a staging site, you would want to take a look at our guide using the link below:
https://www.wpbeginner.com/wp-tutorials/how-to-create-staging-environment-for-a-wordpress-site/
Administrador
Oliver
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
You may need to check with your host but from the sound of it, you would modify the second one.
Administrador
Aldo Salim
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?
WPBeginner Support
As long as you’ve moved all of the files you can remove the sub-directory folder
Administrador
Joshua Orizu
I am building a websites and the domain name is displaying site.comp50 instead of site.com how do i fix this
WPBeginner Support
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
Administrador
Jeremy
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,
WPBeginner Support
This method would overwrite the old content on your primary site, for moving the site you could use one of the methods here: https://www.wpbeginner.com/wp-tutorials/how-to-create-staging-environment-for-a-wordpress-site/
or you could import the content from your live site and then follow the steps in this article
Administrador
Madison
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?
WPBeginner Support
For that type of change, you would want to take a look at our article here: https://www.wpbeginner.com/wp-tutorials/how-to-properly-move-wordpress-to-a-new-domain-without-losing-seo/
Administrador
Madison
Thanks! From what it looks like, all I need to do is not use Duplicator on my root domain but on my subdomain and everything should work the same, right?
WPBeginner Support
That should be correct
jeff
velvet blues didn’t work for me, but another url replacement plugin did (better search replace)
WPBeginner Support
Thanks for sharing the plugin that worked for you
Administrador
Rui
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
You may want to ensure steps 3 and 4 were completed for the most common reason for that.
Administrador
Canonical Bear
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.
John
CANONICAL BEAR, you deserve two kisses for this comment. No, make that three! Worked superbly.
Milan
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!
Melind
This worked like a charm! The part that takes the longest is uploading and downloading the files. Thank you!
smv
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.
Gábor Sztárcsevics
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
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.
Administrador
Shravan
RewriteCond %{HTTP_HOST} ^yoursubdomain\.example\.com$
in this code, do i need to remove those 2 backward slash’s
Denise
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.
WPBeginner Support
Hi Denise,
IF your root site already has a WordPress installation, then you need to overwrite those files.
Administrador
Charlotte Jones
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.
Jon
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.
Juan F.
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
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
Ousman Faal
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.
Kumaar Dev Sharma
this is very helpful to me….very nice post