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

Jak prawidłowo przenieść WordPress z subdomeny do domeny głównej

Uwaga redakcyjna: Otrzymujemy prowizję z linków partnerskich na WPBeginner. Prowizje nie mają wpływu na opinie i oceny naszych redaktorów. Dowiedz się więcej o Proces redakcyjny.

Czy chcesz przenieść witrynę WordPress z subdomeny do domeny głównej?

Proces ten jest dość łatwy do naśladowania i istnieje również sposób na uratowanie twojego rankingu SEO.

W tym artykule pokażemy krok po kroku, jak łatwo przenieść WordPress z subdomeny do domeny głównej.

Moving a WordPress site from subdomain to root domain

Przenoszenie WordPressa z subdomeny do domeny głównej

Subdomena jest rozszerzeniem twojej głównej nazwy domeny. Na przykład http://yourwebsite.example.com jest subdomeną example.com. W tym przypadku domeną główną jest example.com.

Wyszukiwarki uznają subdomenę za zupełnie inną witrynę internetową. Z tego powodu należy upewnić się, że po przeniesieniu odpowiednio przekierowujesz wyszukiwarki do domeny głównej. Pomoże to zachować rankingi wyszukiwania po przeniesieniu twojej witryny internetowej.

W przeciwieństwie do przenoszenia witryny WordPress na nowego hosta lub nową nazwę domeny, przeniesienie witryny do domeny głównej jest nieco łatwiejsze.

Przede wszystkim dlatego, że oba są zwykle hostowane przez tę samą firmę hostingową. Pozwala to pominąć kilka kroków.

Przyjrzyjmy się, jak przenieść witrynę WordPress z subdomeny do domeny głównej.

Krok 1. Utwórz pełną kopię zapasową twojej witryny internetowej

Zawsze powinieneś mieć zainstalowane rozwiązanie do tworzenia kopii zapasowych na twojej witrynie internetowej w celu automatycznego tworzenia kopii zapasowych. Istnieje wiele wtyczek do tworzenia kopii zapas owych WordPress, których możesz użyć, aby zapewnić bezpieczeństwo twojej treści WordPress.

Teraz, jeśli masz już zainstalowaną wtyczkę do tworzenia kopii zapasowych, możesz pomyśleć, że możesz pominąć ten krok.

Ten krok ma na celu przypomnienie, że nawet jeśli masz zautomatyzowane kopie zapasowe twojej witryny internetowej, nadal musisz utworzyć pełną kopię zapasową witryny. Obejmuje to kopię zapasową bazy danych, a także kopię zapasową wszystkich plików i katalogów WordPress.

Po utworzeniu kompletnej kopii zapasowej upewnij się, że przechowujesz ją w zdalnej lokalizacji lub na twoim komputerze.

Krok 2. Przenoszenie twoich plików WordPress z subdomeny do katalogu głównego

Najpierw musisz połączyć się z twoją witryną internetową za pomocą klienta FTP lub menedżera plików cPanel. Po połączeniu przejdź do lokalizacji twojego podfolderu i pobierz wszystkie pliki WordPress na swój komputer.

Download WordPress files

Następnie otwórz katalog public_html twojej domeny głównej. W zależności od tego, jak skonfigurowane jest twoje środowisko hostingowe WordPress, katalog ten może być również nazwany www lub po nazwie twojej domeny.

Teraz musisz przesłać wszystkie pobrane wcześniej pliki WordPress do katalogu głównego.

Upload WordPress files to root domain

Krok 3. Zmiana adresu URL WordPress i ustawień adresu URL witryny

Po przeniesieniu plików WordPress nie będzie można uzyskać dostępu do obszaru administracyjnego WordPress w domenie głównej. Próba logowania się do głównej witryny internetowej spowoduje odesłanie do obszaru administracyjnego witryny subdomeny.

Aby to poprawić, przełącz się na klienta FTP i przejdź do katalogu głównego twojej domeny. Następnie należy edytować plik wp-config.php i dodać następujące linie tuż przed linią „To wszystko, przestań edytować! Happy blogging”.

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

Nie zapomnij zastąpić example.com twoją własną nazwą domeny. Jeśli chcesz, aby twoja główna witryna internetowa korzystała z www, będziesz musiał wpisz adresy URL z prefiksem www.

Zapisz wprowadzone zmiany i prześlij plik wp-config.php z powrotem na swoją witrynę internetową.

Możesz teraz przejść na obszar administracyjny twojej witryny WordPress w domenie głównej.

Krok 4. Aktualizacja adresów URL

Twoja witryna WordPress została przeniesiona do domeny głównej, ale w bazie danych WordPress będą znajdować się odnośniki wskazujące na subdomenę.

Poprawmy to.

Będziesz musiał zainstalować i włączyć wtyczkę Search & Replace Everything. Aby uzyskać więcej informacji, zobacz nasz przewodnik krok po kroku, jak zainstalować wtyczkę WordPress.

Po włączaniu należy przejść na stronę Narzędzia ” WP Wyszukaj i zamień z twojego panelu administracyjnego WordPress.

W górnej części strony wpisz adres URL subdomeny obok pola „Wyszukaj” i dodaj domenę główną w polu „Zamień na”.

Add subdomain and root domain to search and replace fields

Po przewinięciu strony w dół można wybrać aktualizację adresów URL w określonych tabelach w bazie danych WordPress, takich jak twoje wpisy, komentarze, opcje, dane użytkownika, taksonomia i inne obszary. Możesz też wybrać wszystkie tabele.

Następnie kliknij przycisk „Podgląd wyszukiwania i zamiany”.

Select all tables in Search & Replace Everything

Wtyczka wyświetli podgląd wszystkich wprowadzonych zmian.

Jeśli wszystko wygląda w porządku, kliknij przycisk „Zastąp wszystko”, aby kontynuować.

Preview changes and click Replace All

Wtyczka zaktualizuje teraz wszystkie adresy URL w twojej bazie danych WordPress.

Krok 5. Przekierowanie całego ruchu z subdomeny do domeny głównej

Teraz, gdy przeniosłeś już pliki WordPressa, upewnijmy się, że ruch z Twojej subdomeny jest przekierowywany do domeny głównej.

Przejdź do katalogu twojej subdomeny i upewnij się, że ukryte pliki muszą być widoczne.

Ustawienia twojego klienta FTP mają opcję, aby zawsze pokazywać ukryte pliki. W FileZilla znajduje się ona pod opcją Server ” Force Showing Hidden Files.

Show hidden files

Jeśli korzystasz z Menedżera plików cPanel, kliknij przycisk „Ustawienia” w prawym górnym rogu ekranu. Spowoduje to wyświetlenie wyskakującego okienka preferencji. Musisz wybrać opcję „Pokaż ukryte pliki”, a następnie kliknąć przycisk „Zapisz”.

Show hidden files in cPanel file manager

Jeśli twój katalog subdomeny ma już plik.htaccess, możesz go usunąć i utworzyć nowy. Wewnątrz nowego pliku .htaccess należy skopiować i wkleić następujący kod:

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

Nie zapomnij zastąpić subdomeny rzeczywistą subdomeną, a example.com nazwą twojej domeny.

Należy pamiętać, że linia RewriteRule używa adresu URL innego niż www. Jeśli chcesz używać www w domenie głównej, musisz dodać twój adres URL z prefiksem www.

Zapisz swoje zmiany i prześlij plik .htaccess na serwer.

To wszystko. Udało ci się przenieść twoją witrynę z subdomeny do domeny głównej. Możesz teraz przejść na swoją witrynę internetową, aby zobaczyć ją w działaniu. Przetestuj swoją witrynę internetową, aby upewnić się, że wszystko działa poprawnie.

Mamy nadzieję, że ten artykuł pomógł ci przenieść twoją witrynę z subdomeny do domeny głównej. Możesz również zapoznać się z naszym najlepszym przewodnikiem SEO WordPress dla początkujących, a także z naszymi najlepszymi wtyczkami do przekierowania 404 dla 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.

Ujawnienie: Nasze treści są wspierane przez czytelników. Oznacza to, że jeśli klikniesz na niektóre z naszych linków, możemy otrzymać prowizję. Zobacz jak WPBeginner jest finansowany, dlaczego to ma znaczenie i jak możesz nas wspierać. Oto nasz proces redakcyjny.

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.

Najlepszy zestaw narzędzi WordPress

Uzyskaj BEZPŁATNY dostęp do naszego zestawu narzędzi - zbiór produktów i zasobów związanych z WordPressem, które każdy profesjonalista powinien mieć!

Reader Interactions

65 komentarzyZostaw odpowiedź

  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. Jiří Vaněk says

    Previously, I rewrote the URL using phpMyAdmin directly in the database, which was tedious for me. That’s why I was interested in the Go Live Update URLs plugin mentioned in the article. Thanks for the tip; according to the description, I feel that it will significantly speed up my migration work and I won’t have to make changes manually via the MySQL database. Great tip.

  3. 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.

      Administrator

  4. 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.

  5. 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

  6. 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?

  7. 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.

  8. 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.

      Administrator

    • 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.

      Administrator

    • 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

      Administrator

  9. 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.

      Administrator

  10. 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

  11. 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?

  12. 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.

      Administrator

  13. 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?

  14. 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

      Administrator

  15. 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,

  16. 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?

  17. 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.

      Administrator

    • 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.

  18. 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!

  19. Melind says

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

  20. 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.

  21. 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.

      Administrator

  22. Shravan says

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

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

  23. 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.

  24. 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.

  25. 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.

  26. 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

  27. 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.

Zostaw odpowiedź

Dziękujemy za pozostawienie komentarza. Pamiętaj, że wszystkie komentarze są moderowane zgodnie z naszymi polityka komentarzy, a Twój adres e-mail NIE zostanie opublikowany. NIE używaj słów kluczowych w polu nazwy. Przeprowadźmy osobistą i konstruktywną rozmowę.