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

Så här flyttar du WordPress från subdomain till rotdomän på rätt sätt

Vill du flytta en WordPress site från subdomain till rotdomän?

Behandlingen är ganska enkel att följa, och det finns ett sätt att save your sökmotorsoptimering ranking också.

I den här artikeln visar vi dig hur du enkelt flyttar WordPress från subdomain till rotdomän med steg-för-steg-instruktioner.

Moving a WordPress site from subdomain to root domain

Överföring av WordPress från subdomain till rotdomän

En subdomain är en utökning av ditt root domain name. Till exempel är http://yourwebsite.example.com en subdomain för example.com. I det här fallet är example.com rotdomänen.

Search engines betraktar subdomainen som en helt annan website. Det är därför du måste se till att du korrekt redirectar search engines till rotdomänen efter överföringen. Detta hjälper dig att bevara search ranking efter att du har flyttat din website.

Till skillnad från att flytta en WordPress-webbplats till en ny server eller ett nytt domain name är det lite enklare att flytta en site till rotdomänen.

Främst för att båda vanligtvis är hosted med samma webbhotell. Detta allow you att hoppa över några steg.

Låt oss ta en titt på hur du flyttar en WordPress site från subdomain till rotdomän.

Step-by-Step 1. Skapa en komplett backup av din website

Du bör alltid ha en backup-lösning installerad på din website för automatiserade säkerhetskopior. Det finns gott om tillägg för backup av WordPress som du kan använda för att skydda ditt WordPress content.

Nu, om du redan har ett backup plugin installerat, kanske du tänker att du kan hoppa över det här steget.

Detta steg är för att påminna dig om att även om du har automatiserade backuper av din website, måste du fortfarande skapa en komplett backup av din site. Detta inkluderar en backup av databasen samt en backup av alla dina WordPress-filer och -folders.

När du har completed en komplett backup ska du se till att du lagrar den på en avlägsen location eller på din dator.

Step-by-Step 2. Flytta dina WordPress-filer från subdomain till rotmapp

Först måste du ansluta till din website med hjälp av en FTP-klient eller cPanels filhanterare. När du är ansluten går du till din undermapps location och downloadar alla dina WordPress-filer till din dator.

Download WordPress files

Öppna sedan foldern public_html på din domän. Beroende på hur ditt WordPress webbhotell är konfigurerat kan den här foldern också heta www eller efter ditt domain name.

Nu måste du uploada all WordPress-filer som du downloadade tidigare till root directory.

Upload WordPress files to root domain

Step-by-Step 3. Ändra inställningar för WordPress URL och Site URL

När du har flyttat WordPress-filerna kommer du ej att kunna komma åt WordPress admin area på rotdomänen. Om du försöker logga in på rotwebbplatsen kommer du att skickas tillbaka till subdomain-webbplatsens admin area.

För att fixa detta byter du till FTP-klienten och går till rotkatalogen för ditt domain name. Följaktligen måste du editera filen wp-config.php och add to följande rader precis före raden ”That’s all, stop editing! Trevligt bloggande”.

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

Glöm inte att ersätta example.com med ditt eget domain name. Om du vill att din root website ska använda www, måste du enter URL:erna med www-prefix.

Save dina ändringar och upload filen wp-config.php tillbaka till din website.

Du kan nu besöka din WordPress site admin area på rotdomänen.

Step-by-Step 4. Update URL:er

Din WordPress site har flyttats till rotdomänen, men det kommer att finnas links i din WordPress database som pekar på subdomänen.

Låt oss fixa det.

Du måste installera och aktivera pluginet Search & Replace Everything. För mer detaljer, se vår steg-för-steg guide om hur du installerar ett plugin för WordPress.

Efter aktivering måste du besöka Tools ” WP Search & Replace page från din WordPress adminpanel.

Högst upp på sidan måste du enter din subdomains URL bredvid fältet ”Search for” och add to din rotdomän i fältet ”Replace with”.

Add subdomain and root domain to search and replace fields

När du rullar ner på sidan kan du välja att uppdatera URL:er i specifika tabeller i din WordPress database, som gillar dina posts, comments, options, user data, terms och andra areas. Eller så kan du selecta alla tabeller.

Klicka sedan på knappen ”Preview Search & Replace”.

Select all tables in Search & Replace Everything

Tillägget visar dig sedan en preview av alla ändringar som det kommer att göra.

Om allt ser bra ut klickar du på knappen ”Replace All” för att fortsätta.

Preview changes and click Replace All

Plugin kommer nu att update alla URL:er i din WordPress databas.

Step-by-Step 5. Redirect all subdomain-trafik till rotdomänen

Nu när du har flyttat WordPress-filer ska vi se till att din subdomains trafik redirectas till rotdomännamnet.

Gå till din subdomain folder och se till att dolda filer är tvingade att vara synliga.

Your FTP client settings har ett alternativ för att alltid visa dolda filer. I FileZilla finns det under alternativet Server ” Force Showing Hidden Files.

Show hidden files

Om du använder cPanel File Manager klickar du på knappen ”Settings” högst upp till höger på vyn. Då visas popupen med alternativen. You need to select ’Show hidden files’ and then click on the ’Save’ button.

Show hidden files in cPanel file manager

Om din subdomain folder redan har en .htaccess-fil, kan du ta bort den och skapa en new. I den nya .htaccess-filen måste du kopiera och paste in följande kod:

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

Glöm inte att ersätta din subdomain med din faktiska subdomain och example.com med ditt domain name.

Vänligen observera att RewriteRule-raden använder en icke-www URL. Om du vill använda www i din rotdomän måste du add to din URL med ett www-prefix.

Save your changes and upload your .htaccess file to the server.

Det var allt. Du har utan problem flyttat din site från subdomain till rotdomän. You kan nu besöka din website för att se den i action. Testa din website för att se till att allt fungerar som det ska.

Vi hoppas att den här artikeln hjälpte dig att flytta din site från subdomain till rotdomän. Du kanske också vill se vår ultimata guide till sökmotorsoptimering för WordPress för nybörjare, samt våra val av de bästa tilläggen för 404 redirect för 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.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

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.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

67 kommentarerLämna ett svar

  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.

      Administratör

  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.

      Administratör

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

      Administratör

  9. Mucha says

    please advise on the steps for the htaccess. if my subdomain is /new what should it be on the new htaccess?

    • 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

      Administratör

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

      Administratör

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

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

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

      Administratör

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

    • WPBeginner Support says

      As long as you’ve moved all of the files you can remove the sub-directory folder

      Administratör

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

      Administratör

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

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

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

      Administratör

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

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

  20. Melind says

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

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

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

      Administratör

  23. Shravan says

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

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

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

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

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

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

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

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.