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 installerar du WordPress i en subdirectory (steg för steg)

Att installera WordPress i en subdirectory kan vara mycket användbart. Det gör att du kan run flera WordPress webbplatser under samma domän.

Den här inställningen är perfekt för att organisera content. Det hjälper också till att hantera olika projekt utan att påverka huvudwebbplatsen.

I den här guiden visar vi hur du installerar WordPress i en subdirectory. Behandlingen är enkel och kommer inte att påverka din parent domän.

Till slut har du en new WordPress site igång i en subdirectory.

Installing WordPress in a subdirectory or folder

Subdomain vs. Subdirectory: Vilken är bättre för sökmotorsoptimering?

Normalt sett vill du starta en WordPress website på ett eget domain name (till exempel wpbeginner.com).

Ibland kan du dock vilja skapa ytterligare websites med samma domain name.

Detta kan göras genom att antingen installera WordPress i en subdomain (http://newebsite.example.com) eller som en subdirectory (http://example.com/newwebsite/).

En fråga som vi får är vilken som är bäst för sökmotorsoptimering.

Search engines behandlar subdomains på ett annat sätt än root domain names och tilldelar rankning som separata websites.

Till exempel anser search engines att WPBeginner och våra WPBeginner Videos webbplatser är separata webbplatser.

Å andra sidan drar underkataloger direkt nytta av rotdomänens auktorisering och rankas därför högre i de flesta fall.

Ett sätt att skapa separata WordPress webbplatser i både subdomäner eller subdirectories är att installera ett WordPress multisite network.

Men om du vill att två websites ska hanteras separat kan du installera olika instanser av WordPress.

Du kan också använda WordPress tools för site management för att skapa en enda dashboard för att hantera flera WordPress installationer.

Obligatoriska förutsättningar för att installera WordPress i subdirectory

Det finns inga särskilda obligatoriska krav för att installera WordPress i en subdirectory. Om du redan har en WordPress website i root domain name är det bara att köra.

Men om du har en statisk (icke-WordPress) website kan du behöva kontrollera med ditt webbhotell om de har support för WordPress.

Om de inte gör det måste du flytta din website till ett annat webbhotell.

Vi rekommenderar att du använder Bluehost. De erbjuder en generös rabatt på webbhotell till WPBeginners användare med ett gratis domain name.

Om du använder en annan hosting provider, så gör alla de högst upp WordPress hosting företag det mycket enkelt att installera flera WordPress webbplatser med samma hosting konto.

Om du till exempel använder Bluehost kan du lägga till en new WordPress website från din dashboard på webbhotellet.

Bluehost add new site

Kom dock vänligen ihåg att de flesta konton för delade webbhotell har limiterade resurser på servern.

En plötslig trafikökning på en av yours websites kommer att påverka prestandan och hastigheten på all andra websites på samma account.

Om du precis har börjat kan du göra det på ett delat webbhotell. Kom ihåg att du måste uppgradera till hanterat webbhotell för WordPress i takt med att ditt företag växer.

Med detta sagt, låt oss titta på hur du enkelt installerar WordPress i en subdirectory.

Step-by-Step 1: Skapa en subdirectory under rotdomännamnet

Först måste du skapa en subdirectory eller en folder under huvudwebbplatsen. Det är här du kommer att installera WordPress-filer.

Anslut till ditt WordPress webbhotell account med hjälp av en FTP-klient eller File Manager i cPanel.

När du är ansluten går du till din websites rotmapp, som vanligtvis är mappen /public_html/.

Du kommer att se dina WordPress-filer och -foldrar om du redan har WordPress installerat i rotmappen.

Högerklicka sedan och välj ”Create new directory” i menyn.

Create new directory

You need to be careful when choosing the name for your subdirectory. Detta kommer att vara en del av din nya WordPress sites URL och vad dina användare kommer att skriva i sina webbläsare för att nå denna website.

Om du till exempel döper denna directory till travel-guides, kommer adressen till din WordPress website att vara:

http://example.com/travel-guides/

New subdirectory created

Steg 2: Uppladda WordPress-filer

Din nyligen skapade subdirectory är tom för tillfället. Låt oss ändra på det genom att uploada WordPress-filer.

Först måste du besöka WordPress.org website och klicka på knappen ”Download”.

Download WordPress

Din webbläsare kommer nu att downloada zip-filen med den senaste WordPress-programvaran till din dator.

När du har downloadat filen måste du selecta och extrahera den.

Mac-användare kan dubbelklicka på filen för att extrahera den, och Windows-användare måste högerklicka och sedan välja alternativet ”Extract All”.

Extract WordPress

När du har extraherat ZIP-filen kommer du att se en ”wordpress” folder.

I wordpress-mappen finns alla filer och mappar som tillhör WordPress core.

WordPress files

Nu ska vi uploada dessa filer till din new subdirectory.

Anslut till din website med en FTP-klient och gå till subdirectory som du skapade i det första steget.

I panelen för lokala filer i din FTP-klient går du till mappen ”wordpress” som du just extraherade.

Välj alla filer i mappen och uploada dem sedan till your new subdirectory.

Upload WordPress files

Step-by-Step 3: Skapa en ny databas

WordPress lagrar allt ditt content i en database. Du måste skapa en ny database med din nya site WordPress installerad i en subdirectory.

Först loggar du in på instrumentpanelen på ditt WordPress-webbhotell och klickar på knappen ”Settings” under din website.

Bluehost site settings

Därefter växlar du till tabben ”Advanced” från menyn högst upp.

Rulla ner lite till section cPanel och klicka sedan på ”Manage”.

Launch cPanel dashboard in Bluehost

Detta kommer att starta cPanel eller den avancerade kontrollpanelen för webbhotell.

Därifrån måste du klicka på ”MySQL Databases” under sektionen Databases.

cPanel mysql database

Note: Din dashboard på webbhotellet kan se annorlunda ut än screenshoten ovan. You simply need to locate the ’Databases’ section.

På nästa vy enter du namnet på din nya database och klickar på knappen ”Create Database” för att fortsätta.

Create new MySQL database

Din cPanel dashboard kommer nu att skapa den nya MySQL-databasen. Klicka på knappen ”Go Back” för att återgå till sidan Databases.

Därefter måste du add to ett användarnamn och password för databasen.

Rulla bara ner till ”MySQL Users” section och ange ett nytt användarnamn och password. Klicka på knappen ”Skapa användare” för att fortsätta.

Adding new MySQL user

Därefter måste du ge den här nyskapade användaren behörighet att arbeta i den database du skapade tidigare.

Rulla ner till sektionen ”Add user to database” (Lägg till användare i databasen). Välj ditt användarnamn för MySQL och välj sedan din nyskapade database.

Add user to database

Klicka på knappen ”Add” för att fortsätta.

Cpanel kommer nu att ge MySQL-användaren fullständiga behörigheter på din nyskapade database.

Steg 4: Installera WordPress

Nu när allt är på plats kan du gå vidare och installera WordPress.

Besök den directory du skapade tidigare i en web browser genom att skriva in URL:en så här:

http://example.com/your-subdirectory-name/

Då kommer du till installationsguiden för WordPress. Välj först språket för din website i WordPress och klicka på knappen ”Fortsätt”.

WordPress select language

Därefter kommer du att bli ombedd att ange ditt WordPress-databasnamn, databasens användarnamn, lösenord och server.

Enter the database details and click on the ”Submit” button.

WordPress database details

WordPress kommer nu att anslutas till din database.

När anslutningen är klar ser du ett ”success message” som gillar detta:

Database connected

Klicka på knappen ”Run the install” för att fortsätta.

På nästa vy kommer du att bli ombedd att ange en Rubrik för din website och välja ett användarnamn, password och email address för admin.

Enter website details

När du har enter detaljerna för din website klickar du på knappen ”Run install” för att fortsätta.

WordPress kommer nu att konfigurera din website och visa dig ett success message:

WordPress install finished

Nu kan du logga in på din new website WordPress, som är installerad i subdirectory.

Step 5: Fixa permalänkar

Om du har en separat WordPress install i rotkatalogen kommer .htaccess-filerna i din subdirectory att orsaka konflikt. Detta kommer att resultera i 404 error på din website.

För att lösa detta måste du editera .htaccess-filen i din subdirectory WordPress install. Ersätt koden i din .htaccess-fil med följande kod:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /your-subdirectory/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /your-subdirectory/index.php [L]
</IfModule>
 
# END WordPress

Glöm inte att ersätta /your-subdirectory/ med namnet på din subdirectory.

Vi hoppas att den här artikeln hjälpte dig att installera WordPress i en subdirectory. Du kanske också vill se vår ultimata Step-by-Step WordPress sökmotorsoptimering guide för nybörjare.

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

89 kommentarerLämna ett svar

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

  2. John Pana

    Can I integrate a WordPress blog as a subdirectory (e.g., abc.com/blog) with my existing Ruby on Rails website? If so, are there any specific steps I need to follow to achieve this setup?

    • WPBeginner Support

      Unless Ruby on Rails would override the file structure, you should be able to follow the steps in this article and have the site in a subdirectory with WordPress :)

      Administratör

  3. Chanakya Sahu

    Hi, I have created subdirectory using auto-installer feature in Hostinger for my News blog for creating a completely different site for different language. For example:- example.com/language. I am gonna post unique articles here.

    I might also post the translated version here (Not ai translated though, I am gonna translate it myself). Does it affect SEO? Should I translate the some articles or leave it to google?

    • WPBeginner Support

      You would want to check with your SEO plugin to ensure the correct markup is added and it should not affect your SEO.

      Administratör

  4. Prem Krishnan P

    I have installed WordPress on the subdirectory. (i.e)www.example.com/blog) and now I created a test post (i.e.)www.example.com/blog/test. Is it possible to remove the subdirectory from the url? Looking something like this example.com/test (i.e)www. Rootsitename.com/Postname

    • WPBeginner Support

      If you want to do that then we do not have a specific recommendation to achieve that and it would likely be best to place the post on your primary domain to achieve that.

      Administratör

    • Jiří Vaněk

      This can be done using the .htaccess file, which is the Linux apache configuration file. It is possible to upload rules to this file, which can be used to rewrite URL addresses in the browser. However, it is a relatively complex topic and it is necessary to approach such an intervention sensitively.

  5. Yevhenii Korchak

    Thanks for the tutorial! Very helpful. You’re the best :)

    • WPBeginner Support

      Thank you and glad to hear our tutorial was helpful!

      Administratör

  6. Mangkutak

    is this type of wordpress installation still can enable multisite feature if i want it to enable for my wordpress site. i heard that before long time ago that’s not possible, is that still the case today?

    • WPBeginner Support

      You can convert a site to a multisite installation.

      Administratör

  7. Mohammed

    hello,
    I did the same steps, once I installed WordPress and do some tests I found that cannot make save posts or publish them. an error message appears
    Updating failed. The response is not a valid JSON response.
    please help.

  8. alan

    Thanks for this tutorial. I wasn’t sure if I had to previously create the database or make it during the install process.

    • WPBeginner Support

      Glad our guide was helpful!

      Administratör

  9. Giwa

    Hello, this steps are self explanatory but in my case, our main website doesn’t run on WordPress however we want to run WordPress on a sub-directory /blog.
    How do we go about this
    the main website runs on NodeJs

    • WPBeginner Support

      You should still be able to follow the steps in this guide for what you’re wanting to do.

      Administratör

  10. Abid Hasan

    Today I’ve set up my new WordPress inside sub-directory. Didn’t need to change the .htaccess file. I think WP is so smart now that can handle this automatically.

    • WPBeginner Support

      Thanks for sharing, your hosting provider may have also set it up for you when installing as certain hosts set that up for you now. :)

      Administratör

  11. Goran

    Thanks a lot for great tutorial whithout any issues.

    • WPBeginner Support

      Glad our guide was helpful :)

      Administratör

  12. Sam

    Thank you for this guide.

    We are planning to have subdirectories on our next website. This guide really cleared the air.

    One question though,

    Is there a limited to how many subdirectories a WordPress website can have?

    • WPBeginner Support

      There is not a hard limit to the number of directories at the moment.

      Administratör

  13. Swetha

    Hi.. thanks for this article… am unable to upload the folders wp-admin, wp-content and wp-includes in the sub directory… rest other files are uploaded.. how do I upload all of these???

    • WPBeginner Support

      It would depend on why you are unable, if you reach out to your hosting provider they should be able to assist but it may be a permissions issue with your user.

      Administratör

  14. Arinze

    Thanks it worked.
    Is it possible to the subdirectory name on the URL, for example example.com/seo/how-to-rank to example.com/how-to-rank

    • WPBeginner Support

      If you would like your URLs not to have the subdirectory in the URL we would recommend installing the site on your primary domain rather than creating redirects to remove it from the URL.

      Administratör

  15. Arinze

    Thanks for this article. It is very insightful.
    Will the installation of WordPress on the sub folder affect the overall speed of the site.

    • WPBeginner Support

      It should not :)

      Administratör

  16. dennis wille

    there is an apparent error in your htaccess code example

    should be
    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /your-subdirectory/
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /your-subdirectory/index.php [L]

     
    # END WordPress

    note rewriterule line 5 change

    • WPBeginner Support

      Thank you for catching that, while not specifically required, we’ll look to update the article :)

      Administratör

  17. Deddy Hidayat

    I want to build a web with a wordpress subdirectory, the first web is domain.com, and the second web is domain.com/blog … as far as I know wordpress uses domain.com/blog as the default post … will it hurt SEO?

    • WPBeginner Support

      WordPress does not use /blog as a default, that is only the most common URL to use. Using blog for a subdirectory should not have a major effect on SEO.

      Administratör

  18. Shashank Dubbewar

    is it necessary to install and manage same plugins separately if I installed wordpress on main domain and sub directory each and manage wordpress sites separately ?

  19. Mohd Kaleem

    Hello Sir, Can I create Subdirectory without login Cpanel. I forgot My Hosting Details. But I have WP details, is it possible to create subdirectory using wordpress any plugin or other way?

    • WPBeginner Support

      You would need access to your hosting, you should be able to reach out to your hosting provider for assistance in being able to log back into your account.

      Administratör

  20. Kosi

    Thank you. This worked! Really grateful….

    • WPBeginner Support

      You’re welcome, glad our guide was helpful :)

      Administratör

  21. Nicoleiver

    Hi, I would like to ask is it possible to copy all the file from my current folder to the sub directory? Because I want to have the same template and plugin for my sub directory site.

  22. John Doe

    What if the I created a new subdirectory from another subdirectory, should the fix permalink still be relevant and work with no problem?
    For example, I have firstwebsite.com/firstsubdir/ the second subdirectory will be firstwebsite.com/firstsubdir/secsubdir/ should I still use the same fix for the permalink?

    Sorry English is not my first language.

    • WPBeginner Support

      You would need to include the second subdirectory in the permalink change and it should still work.

      Administratör

  23. keram

    Thanks for a clear tutorial.

    Is it possible to install WP in a subdirectory but use the main domain URL to access it and still have the main URL displayed in the browser address bar?
    To clarify:
    I would install WP in mydomain.com/sub/ but would like to access it by opening mydomain.com and have mydomain.com displayed in the browser so that visitors can bookmark my URL.

    Is it possible to set it up?

    • WPBeginner Support

      It is possible but would depend on your hosting provider to see if it is allowed. If you reach out to your hosting provider they should be able to assist.

      Administratör

      • keram

        Will the pages load faster if WP is installed in the subdirectory?

        • WPBeginner Support

          Where your site is installed on your host shouldn’t affect your site’s loading time to a noticeable degree

  24. Ghulam Mujtaba

    Salam, I just finished reading the article and i have question, how can i have the same header and footer from the wordpress installation in parent directory? I’ll be glad and thankful to you if you give me a clue, Thanks…

    • WPBeginner Support

      For that, the simplest method would be to install the same theme on both sites.

      Administratör

  25. Priscilla

    Hello,
    Thans for this awsome tuto, it works!

    • WPBeginner Support

      Glad our guide was helpful :)

      Administratör

  26. Sohail

    Really helpful! One question please.

    Do I have to add this line:

    RewriteBase /your-subdirectory/

    for every install in a sub directory in main WordPress installation?

    Thanks

    • WPBeginner Support

      Yes, we would recommend this to prevent any issues on the subdirectory

      Administratör

  27. Samantha

    Thank you for this information! Helped me a lot!

    • WPBeginner Support

      You’re welcome, glad our guide could help :)

      Administratör

  28. Alex

    Hi. I manually copied my Wordpress files to the root folder, without the plugin. I then copied the original database in a new one, where I replaced the siteurl to reflect the new location, the root folder. In the wp-config file at the root folder, I changed WP_HOME and WP_SITEURL to remove the /wordpress.

    As a result, I was able to reach the wp-login for my new location, but no further.

    And when I visited my site, I was getting a warning ”too many redirections”.

    Any advice?

  29. Abhishek mahajan

    Thanks a lot for WP subfolders step by step guide. One thing that i never undersatnd is how to create a exact Google news xml sitemap in WordPress?

    • WPBeginner Support

      Most SEO plugins should add the required markup for you to be able to be added to Google News. If you are using an SEO plugin you would want to reach out to the plugin’s support for what they recommend for setttings.

      Administratör

  30. Hesam

    Thanks for your article. I have a question about transforming this sub domain or sub directory installed word press to main root of website and replace it with the main site. what should I do?

  31. Umesh Yellaboina

    Hi Team, Thanks for this post, not only these… all the other posts in your blog are very helpful to us, I really appreciate your works. Thanks a lot for these.

    And need a little help, actually did the same as in this post, installed wordpress in a sub directory, but I’m face a little issue, i.e. I’m unable to receive the emails from contact form, when it was on sub-domain it’s working fine, but when it is installed on sub-directory not receiving the form submissions, it’s going on loading but not getting submitted. Please help me with this. Thank you.

  32. David

    Thanks for the info. I read every post you write.

    Just I’ve a doubt. I created a new WP Install trough my Host provider, but searching, there is no .htaccess file in the subdirectory. It’s mandatory to have a new .htaccess file? it’s going to create errors in the future?

    • WPBeginner Support

      WordPress should generate the htaccess file if you resave your permalinks. If you still don’t see it you may not have the option to show hidden files enabled :)

      Administratör

  33. Rubens

    thankkkkkkkssssssss <3

    • WPBeginner Support

      You’re welcome :)

      Administratör

  34. Eulises Quintero

    Hello, I successfully installed WordPress in a subdirectory around 3 weeks ago, I already uploaded a theme, some plugins and made some posts. Question, can I change the name of my subdirectory? How? the name is Chose for my subdirectory and what shows after my original website URL is español, I want to make it es, I want to change this because I read somewhere that characters like ñ might cause some issues in terms of SEO….so now I’m worried, thank you for your time

  35. Mosiur Rahman

    Hey, I just followed the process except i haven’t changed the htaccess file. My site is still working properly. I am using hostinger.

    is changing the htaccess mandatory ? will it cause error in the future?

    • WPBeginner Support

      Your host may have set up the redirect for you, if you reach out to your host they should be able to let you know.

      Administratör

  36. Owaiz Yusufi

    Just got it to work but little bit worried, does it increases my load time of both pages. I mean to say that

    ( currently I have made this on localhost for test but I am going to implement it in one or two days on my main server )

    I have two website but single domain

    Just want to know that does this will increase the bandwidth useage and load time.

    Let’s suppose if I my main webpage size 1 mb and my second website size is also 1 mb so when someone load the main page does it loads all the 1+1 2mb size.

    • WPBeginner Support

      Hi Owaiz,

      Yes it will increase bandwidth usage depending on your traffic. Since both WordPress installs share the resources, traffic load on one website will affect the performance of other website as well.

      Administratör

  37. billybob

    Wow, worked first time! Thank you so much!!

  38. maxime

    Thank you very much, clear and working :)

  39. Mauwiks

    My site got a white screen of death after this.

  40. Shankar

    Really Its very useful for beginners to install

  41. Karen

    Hello, I dont understand something. What is the difference between installing wordpress in a subdirectory and just creating multiple pages???

    I am a noob

  42. Simson

    I think I did everything as shown in your instructions. But the trouble I’m having is when I’m trying to customize my theme on the subdirectory it taking me to the root domain wp customizer. What should I do then… ?

  43. Yoki andika

    Hello, can you help me?

    I installed my local wordpress to the subdir with ftp but the problem is the css doesn’t work properly, and i don’t know what’s wrong with my wordpress, because i follow this step.
    Maybe Anyone can help?

    Thank you

  44. Kandra

    Hi,

    I am following the steps that you have recommended in creating the sub directory, but than I see the following error,

    When I trying to open the URL after uploading all the files to the folder through FTP,
    I see the URL redirecting to wp-admin/setup-config.php & throwing an server error 500 (This page isn’t working
    simplyrent.in is currently unable to handle this request.
    HTTP ERROR 500)

  45. Jyotishman Nath

    I have heard that subdirectories are treated as part of root domain in terms of ranking.But my subdirectory is not ranking, even for exact match keyword search.I have indexed Subdirectory using Fetch as Google Tool.I don’t know what is the problem?

    I have submitted it to Search Console, Created separate robot.txt and sitemap (Sitemap is pending from last two days).

    Should I give more time to Google to Crawl by Subdirectory?

    Please Replay.
    Thanks!

    • WPBeginner Support

      Hi Jyotishman,

      It is up to search engines to decide how they would rank your website in their results. All you can do is optimize your website for SEO and follow the best practices.

      Administratör

  46. Layon

    Thank you for this tutorial. It saved me after hours trying to understand why I was getting 404 errors all day long.

  47. Johnny

    just put this in your .htaccess
    DirectoryIndex index.php
    thank me later!

  48. TH

    Question: Login for main and subdirectory

    Hi. I created a subdirectory with a separate WP install.
    It looks like the user has to create an account for the main and subdirectory and to login for both the main and subdirectory.

    Is there a way to let a user who has login to either the main or subdirectory site to have access to the other site without having to login again? i.e if user has login into main site, he/she does not need to login to the subdirectory site. and vice versa.

    Thanks.

    TH

  49. Dragos

    By default, if you are using softaculous, you are installing wordpress to the default directory named wp. You don’t need to install manually WordPress in a directory/ subdomain, you only need to change the name of the directory where you want Softaculous to install WordPress and it will also make a database and so on. :)

  50. medmouncef

    Thanks for this tutorial.
    It would be interesting to show, when you have a little time of course, how to configure cPanel redirects to this subdirectory. For example, I can’t redirect my domain name to a Wordpress subdirectory créé sous /public-html.

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.