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 optimerar du din Robots.txt i WordPress för sökmotorsoptimering

Senast frågade en av våra Läsare oss hur man optimerar filen Robots.txt för att förbättra sökmotorsoptimeringen.

Filen Robots.txt talar om för sökmotorer hur de ska crawla din website, vilket gör den till ett otroligt kraftfullt verktyg för sökmotorsoptimering.

I den här artikeln kommer vi att visa you några tips på hur du skapar en perfekt Robots.txt-fil för sökmotorsoptimering.

Optimizing robots.txt file for better SEO

Vad är en Robots.txt-fil?

Robots.txt är en textfil som webbplatsägare kan skapa för att tala om för sökmotorrobotar hur de ska crawla och indexera pages på deras webbplatser.

Den lagras vanligtvis i root directory (även känd som huvudfoldern) på din website. Det grundläggande formatet för en Robots.txt-fil gillar detta:

User-agent: [user-agent name]
Disallow: [URL string not to be crawled]
 
User-agent: [user-agent name]
Allow: [URL string to be crawled]
 
Sitemap: [URL of your XML Sitemap]

You kan ha flera rader med instruktioner för att allow eller disallow specifika URL:er och add to flera sitemaps. Om du inte underkänner en URL antar sökmotorns bots att de har behörighet att crawla den.

Så här kan en Robots.txt-fil till exempel gilla att se ut:

User-Agent: *
Allow: /wp-content/uploads/
Disallow: /wp-content/plugins/
Disallow: /wp-admin/

Sitemap: https://example.com/sitemap_index.xml

I exemplet ovan med Robots.txt har vi allowat search engines att crawla och indexera filer i vår WordPress uploads folder.

Därefter förbjöd vi sökrobotar att crawla och indexera tillägg och WordPress admin folders.

Slutligen har vi angett URL:en till vår XML-webbplatskarta.

Behöver du en Robots.txt-fil för din site i WordPress?

Om du inte har en Robots.txt-fil kommer search engines ändå att crawla och indexera din website. Du kommer dock inte att kunna tala om för dem vilka pages eller foldrar de ej ska crawla.

Detta kommer inte att ha någon större inverkan när du först startar en blogg och inte har så mycket content.

Men när din website växer och du addar till mer content kommer du sannolikt att vilja ha bättre control över hur din website crawlas och indexeras.

Här är skälet till detta.

Sökrobotar har en crawl-kvot för varje website.

Det innebär att de crawlar ett visst antal pages under en crawlsession. Om de använder upp sin crawl-budget innan de slutför crawlen av alla pages på your site, kommer de tillbaka och återupptar crawlen i nästa session.

Detta kan sakta ner indexeringshastigheten för din website.

Du kan fixa detta genom att inte tillåta sökrobotar att försöka crawla onödiga pages som gillar your WordPress admin pages, plugin files, and themes folder.

Genom att inte tillåta onödiga pages, save your crawl quota. Detta hjälper search engines att crawla ännu fler pages på din site och indexera dem så snabbt som möjligt.

En annan bra anledning att använda en Robots.txt-fil är när du vill hindra search engines från att indexera ett post eller en page på din website.

Det här är ej det säkraste sättet att dölja content från allmänheten, men det hjälper you att förhindra att content visas i sökresultat.

Hur gillar man en perfekt Robots.txt-fil?

Många populära bloggar använder en mycket enkel Robots.txt-fil. Deras content kan variera beroende på behoven hos den specifika webbplatsen:

User-agent: *
Disallow:

Sitemap: http://www.example.com/post-sitemap.xml
Sitemap: http://www.example.com/page-sitemap.xml

Den här filen Robots.txt allow alla bots att indexera allt content och ger dem en länk till webbplatsens XML sitemaps.

För WordPress webbplatser rekommenderar vi följande regler i filen Robots.txt:

User-Agent: *
Allow: /wp-content/uploads/
Disallow: /wp-admin/
Disallow: /readme.html
Disallow: /refer/

Sitemap: http://www.example.com/post-sitemap.xml
Sitemap: http://www.example.com/page-sitemap.xml

Detta säger till sökrobotar att indexera alla WordPress images och filer. Det förhindrar sökrobotar från att indexera WordPress admin area, readme-fil och cloaked affiliate links.

Genom att lägga till sitemaps i filen robots.txt gör du det enkelt för Googles bots att hitta alla pages på din site.

Nu när du vet hur en perfekt Robots.txt-fil gillar att se ut ska vi ta en titt på hur du skapar en Robots.txt-fil i WordPress.

Så här skapar du en Robots.txt-fil i WordPress

Det finns två sätt att skapa en Robots.txt-fil i WordPress. Du kan välja den metod som fungerar bäst för dig.

Metod 1: Edit Robots.txt-fil med All in One SEO

All in One SEO, även känt som AIOSEO, är det bästa WordPress SEO plugin på marknaden, som används av över 3 miljoner webbplatser. Det är användarvänligt och levereras med en generator för filen robots.txt.

För att lära dig mer, se vår detaljerade AIOSEO review.

Om du inte redan har AIOSEO-pluginet installerat kan du se vår Step-by-Step guide om hur du installerar ett plugin för WordPress.

Note: En gratis version av AIOSEO är också available och har denna funktion.

När pluginet är installerat och aktiverat kan du använda det för att skapa och edit din Robots.txt-fil direkt från din WordPress admin area.

Gå bara till All in One SEO ” Tools för att redigera din robots.txt-fil.

Robots.txt file editor in All in One SEO

Först måste du aktivera alternativet edit genom att klicka på ”Enable Custom Robots.txt” toggle till blått.

Med denna Toggle aktiverad kan du skapa en custom robots.txt-fil i WordPress.

Enable custom robots.txt file

All in One SEO kommer att visa din befintliga robots.txt-fil i avsnittet ”Robots.txt Preview” längst ner på din vy.

Denna version visar standardreglerna som har lagts till av WordPress.

Robots.txt file preview in All in One SEO

Dessa standardregler säger till search engines att inte crawla dina WordPress core-filer, tillåter bots att indexera allt content och ger dem en länk till din sites XML-sitemaps.

Nu kan du add to dina egna custom regler för att förbättra din robots.txt för sökmotorsoptimering.

För att add to en regel, enter en användare i fältet ”User Agent”. Om du Tillämpar en * kommer regeln att tillämpas på alla användare.

Sedan väljer du om du vill ”Allow” eller ”Disallow” att search engines ska crawla.

Därefter anger du filnamnet eller sökvägen till directory i fältet ”Directory Path”.

Add robots file rules

Regeln kommer automatiskt att tillämpas på din Robots.txt. Om du vill add to en ny regel klickar du bara på knappen ”Add Rule”.

Vi rekommenderar att du lägger till regler tills du skapar det perfekta formatet Robots.txt som vi delade ovan.

Dina customize-regler kommer att se ut så här.

Custom robots txt file preview

När du är klar, glöm inte att clicka på knappen ”Save Changes” för att store dina ändringar.

Metod 2: Edit Robots.txt-fil med hjälp av WPCode

WPCode är ett kraftfullt code snippets plugin som låter dig lägga till custom code till din website enkelt och säkert.

Det innehåller också en praktisk funktion som gör att du snabbt kan edit filen Robots.txt.

Note: Det finns också ett WPCode Free Plugin, men det innehåller inte funktionen för filredigerare.

Det första du behöver göra är att installera pluginet WPCode. För Step-by-Step instruktioner, se vår guide för nybörjare om hur du installerar ett WordPress plugin.

Vid aktivering måste du navigera till WPCode ” File Editor page. Väl där klickar du bara på tabben ”robots.txt” för att editera filen.

WPCode robots.txt Editor

Nu kan du klistra in eller skriva in innehållet i filen robots.txt.

När du är slutförd, se till att du klickar på knappen ”Save Changes” längst ner på sidan för att lagra inställningarna.

Metod 3: Redigera filen Robots.txt manuellt med FTP

För den här metoden måste du använda en FTP-klient för att editera filen Robots.txt. Alternativt kan du använda filhanteraren som tillhandahålls av ditt WordPress webbhotell.

Anslut till filerna på din WordPress website med hjälp av en FTP-klient.

När du väl är inne kommer du att kunna se filen robots.txt i din websites root folder.

Edit robots file via FTP

Om du inte ser någon, har du troligen inte en Robots.txt-fil.

I så fall kan du bara gå vidare och skapa en.

Create new robots file

Robots.txt är en ren textfil, vilket innebär att du kan downloada den till din dator och editera den med en ren textredigerare som gillar Notepad eller TextEdit.

När du har saved dina ändringar kan du uploada filen robots.txt tillbaka till din websites root folder.

Så här testar du filen Robots.txt

När du har skapat din robots.txt-fil är det alltid en bra idé att testa den med hjälp av ett robots.txt-testverktyg.

Det finns många verktyg för att testa Robots.txt, men vi rekommenderar att du använder det som finns i Google Search Console.

Först måste du ha din website linkad med Google Search Console. Om du inte har gjort det än, se vår guide om hur du lägger till din WordPress site till Google Search Console.

Sedan kan du använda Google Search Console Robots Testing Tool.

Choose property

Välj bara din fastighet från dropdown-listan.

Tools hämtar automatiskt filen Robots.txt på din website och markerar error och varningar om den hittar några.

Robots tester tool

Slutliga tankar

Målet med att optimera filen Robots.txt är att förhindra search engines från att crawla pages som inte är offentligt available. Till exempel pages i din wp-plugins folder eller pages i din WordPress admin folder.

En vanlig myt bland sökmotorsoptimeringsexperter är att blockering av WordPress kategorier, tags och archive pages kommer att förbättra crawl-hastigheten och resultera i snabbare indexering och högre ranking.

Detta är inte sant. Det är också emot Googles riktlinjer för webbansvariga.

Vi rekommenderar att du följer ovanstående format för robots.txt för att skapa en robots.txt-fil för din website.

Expertguider för användning av Robots.txt i WordPress

Nu när du vet hur du optimerar din Robots.txt-fil kanske du gillar att läsa andra artiklar relaterade till att använda Robots.txt i WordPress.

Vi hoppas att den här artikeln hjälpte dig att lära dig hur du optimerar din Robots.txt-fil för WordPress för sökmotorsoptimering. Du kanske också vill se vår ultimata guide till sökmotorsoptimering i WordPress och våra expertval för de bästa WordPress SEO tools för att få din website att växa.

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

132 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. Dennis Muthomi says

    I have to admit, I use the AIOSEO plugin but have always ignored the ”Enable Custom Robots.txt” option because I didn’t want to mess anything up.
    But I have read this article and I’m convinced it’s worth taking the time to optimize my site’s robots.txt file.

  3. Moinuddin Waheed says

    Thanks for this informative post about robots.txt file.
    I didn’t know that websites should maintain this file in order to have a control over Google bots that how should they crawl over our pages and posts.
    for beginner websites just starting out, is there a need to have robots.txt file or is there a way like plugin which can a make a robots.txt file for our website?

    • WPBeginner Support says

      Most SEO plugins help with setting up the robots.txt for a new site to prevent bots from scrolling sections they shouuldn’t.

      Administratör

  4. Jiří Vaněk says

    Thanks to this article, I checked the robots.txt file and added URL addresses with sitemaps. At the same time, I had other problematic lines there, which were revealed by the validator. I wasn’t familiar with sitemaps in robots.txt until now. Thanks.

  5. Stéphane says

    Hi,

    Thanks for that post, it becomes clearer how to use the robots.txt file. On most websites that you find while looking for some advice regarding the robots.txt file, you can see that the following folders are explicitly excluded from crawling (for WordPress):
    Disallow: /wp-content/plugins
    Disallow: /wp-content/cache
    Disallow: /wp-content/themes

    I don’t really understand the reasons to exclude those folders (is there one actually?). What would be your take regarding that matter?

    • WPBeginner Support says

      It is mainly to prevent anything in those folders from showing as a result when a user searches for your site. As that is not your content it is not something most people would want to appear for the site’s results.

      Administratör

  6. zaid haris says

    Disallow: /wp-admin/
    Allow: /wp-admin/admin-ajax.php

    GSC show the coverage error for ”Disallow: /wp-admin/” Is this wrong?

    • WPBeginner Support says

      For most sites, you do not want anything from your wp-admin to appear as a search result so it is fine and expected to receive the coverage area when you deny Google the ability to scan your wp-admin.

      Administratör

  7. Hansini says

    I am creating my robots.txt manually as you instructed for my WordPress site.

    I have one doubt. when I write User-Agent: * won’t it allow another spamming robot to access my site?
    Should I write User-Agent: * or User-Agent: Googlebot.?

    • WPBeginner Support says

      The User-Agent line is setting the rules that all robots should follow on your site, if you specify a specific bot on that line it would be setting rules for that specific bot and none of the others.

      Administratör

  8. Sanjeev Pandey says

    should we also disallow /wp-content/themes/ ?

    It is appearing in the search result when I run the command site:abcdef.com in google search

    • WPBeginner Support says

      You would not want to worry about blocking your themes folder and as you write SEO-friendly content you should no longer see the themes as a search result.

      Administratör

    • WPBeginner Support says

      That means you’re telling search engines to not look at any referral links or the readme.html file.

      Administratör

    • WPBeginner Support says

      If you block your uploads folder then search engines would not normally crawl your uploaded content like images.

      Administratör

  9. Ravi kumar says

    Sir i m very confused about robot.txt many time i submitted site map in blogger but the after 3,4 days coming the same issue what is the exactly robot.txt.. & how submit that please guide me

    • WPBeginner Support says

      No, Google will not list the page but if the page is listed it will not show an error.

      Administratör

  10. Bharat says

    Hi
    I have a question
    i receive google search console coverage issue warning for blocked by robots.txt
    /wp-admin/widgets.php
    My question is, can i allow for wp-admin/widgets.php to robots.txt and this is safe?

  11. Amila says

    Hello! I really like this article and as I’m a beginner with all this crawling stuff I would like to ask something in this regard. Recently, Google has crawled and indexed one of my websites on a really terrible way, showing the pages in search results which are deleted from the website. The website didn’t have discouraged search engine from indexing in the settings of WordPress at the beginning, but it did later after Google showed even 3 more pages in the search results (those pages also doesn’t exist) and I really don’t understand how it could happen with ”discourage search engine from indexing” option on. So, can the Yoast method be helpful and make a solution for my website to Google index my website on the appropriate way this time? Thanks in advance!

    • WPBeginner Support says

      The Yoast plugin should be able to assist in ensuring the pages you have are indexed properly, there is a chance before you discouraged search engines from crawling your site your page was cached.

      Administratör

      • Amila says

        Well yes and from all pages, it cached the once who doesn’t exist anymore. Anyway, as the current page is on ”discourage” setting on, is it better to keep it like that for now or to uncheck the box and leave the Google to crawl and index it again with Yoast help? Thanks! With your articles, everything became easier!

        • WPBeginner Support says

          You would want to have Google recrawl your site once it is set up how you want.

  12. Pradhuman Kumar says

    Hi I loved the article, very precise and perfect.
    Just a small suggestion kindly update the image ROBOTS.txt tester, as Google Console is changed and it would be awesome if you add the link to check the robots.txt from Google.

    • WPBeginner Support says

      Thank you for the feedback, we’ll be sure to look into updating the article as soon as we are able.

      Administratör

  13. Kamaljeet Singh says

    My blog’s robots.txt file was:
    User-Agent: *
    crawl-delay: 10

    After reading this post, I have changed it into your recommended robots.txt file. Is that okay that I removed crawl-delay

    • WPBeginner Support says

      It should be fine, crawl-delay tells search engines to slow down how quickly to crawl your site.

      Administratör

    • Editorial Staff says

      We use /refer/ to redirect to various affiliate links on our website. We don’t want those to be indexed since they’re just redirects and not actual content.

      Administratör

  14. Sagar Arakh says

    Thank you for sharing. This was really helpful for me to understand robots.txt
    I have updated my robots.txt to the ideal one you suggested. i will wait for the results now

  15. Jasper says

    thanks for update information for me. Your article was good for Robot txt. file. It gave me a piece of new information. thanks and keep me updating with new ideas.

    • WPBeginner Support says

      For a multisite, you would need to have a robots.txt file in the root folder of each site.

      Administratör

  16. Pacifique Ndanyuzwe says

    My wordpress site is new and my robot.txt by default is
    user-agent: *
    Disallow: /wp-admin/
    Allow: /wp-admin/admin-ajax.php

    I want google to crawl and index my content. Is that robot.txt okay?

  17. Ritesh Seth says

    Great Airticle…

    I was confused from so many days about Robots.txt file and Disallow links. Have copied the tags for robots file. Hope this will solve the issue of my Site

  18. Kurt says

    The files in the screenshots of your home folder are actually located under the public_html folder under my home folder.

    I did not have a /refer folder under my public_html folder.

    I did not have post or page xml files anywhere on my WP account.

    I did include an entry in the robots.txt file I created to disallow crawling my sandbox site. I’m not sure that’s necessary since I’ve already selected the option in WP telling crawlers not to crawl my sandbox site, but I don’t think it will hurt to have the entry.

    • WPBeginner Support says

      Some hosts do rename public_html to home which is why you see it there. You would want to ensure Yoast is active for the XML files to be available. The method in this article is an additional precaution to help with preventing crawling your site :)

      Administratör

  19. Elyn Ashton says

    User-agent: *
    Disallow: /wp-admin/
    Allow: /wp-admin/admin-ajax.php <– This is my robot.txt code but im confuse why my /wp-admin is index? How to no index it?

    • WPBeginner Support says

      If it was indexed previously you may need to give time for the search engine’s cache to clear

      Administratör

  20. Ashish kumar says

    This website really inspire me to start a blog .Thank you lost of tema.this website each and every article have rich of information and explanation.when i have some problem at first i visit this blog . Thank You

  21. Anna says

    I am trying to optimise robots for my website using Yoast. However Tools in Yoast does not have the option for ’File Editor’.
    There are just two options
    (i) Import and Export
    (ii) Bulk editor
    May you please advise how this can be addressed. Could it be that I am on a free edition of Yoast?

    • WPBeginner Support says

      The free version of Yoast still has the option, your installation may be disallowing file editing in which case you would likely need to use the FTP method.

      Administratör

  22. Emmanuel Husseni says

    I really find this article helpful because I really don’t know much on how robot.txt works but now I do.

    pls what I don’t understand is how do I find the best format of robot.txt to use on my site (I mean one that works generally)?

    I noticed lots of big blogs I check ranking high on search engine uses different robot.txt format..

    I’ll be clad to see a reply from you or just anyone that can help

    • Editorial Staff says

      Having a sitemap and allowing the areas that need to be allowed is the most important part. The disallow part will vary based on each site. We shared a sample in our blog post, and that should be good for most WordPress sites.

      Administratör

    • WPBeginner Support says

      Hey Emmanuel,

      Please see the section regarding the ideal robots.txt file. It depends on your own requirements. Most bloggers exclude WordPress admin and plugin folders from the crawl.

      Administratör

  23. jack says

    Well written article, I recommend the users to do sitemap before creating and enabling their ROBOTS text it will help your site to crawl faster and indexed easily.

    Jack

  24. Cherisa says

    I keep getting the error message below on google webmaster. I am basically stuck. A few things that were not clear to me on this tutorial is where do I find my site’s root files, how do you determine if you already have a ”robots.txt” and how do you edit it?

    • WPBeginner Support says

      Hi Cherisa,

      Your site’s root folder is the one that contains folders like wp-admin, wp-includes, wp-content, etc. It also contains files like wp-config.php, wp-cron.php, wp-blogheader.php, etc.

      If you cannot see a robots.txt file in this folder, then you don’t have one. You can go a head and create a new one.

      Administratör

      • Cherisa says

        Thank you for your response. I have looked everywhere and can’t seem to locate these root files as you describe. Is there a path directory I can take that leads to this folder. Like it is under Settings, etc?

  25. Devender says

    I had a decent web traffic to my website. Suddenly dropped to zero in the month of May. Till now I have been facing the issue. Please help me to recover my website.

  26. Haris Aslam says

    Hello There Thank you For This Information, But I Have A Question
    That I Just Create The Sitemap.xml and Robots.txt File, & Its Crawling well. But How Can I Create ”Product-Sitemap.xml”
    There is all list of product in sitemap.xml file. Do I Have To Create Product-sitemap.xml separately?

    and submit to google or bing again ?
    Can You please Help me out…
    Thank You

  27. Mahadi Hassan says

    I have a problem on robots.txt file setting. Only one robots.txt is showing for all websites. Please help me to show separate robots.txt file of all websites. I have all separate robots.txt file of all individual website. But only one robots.txt file is showing in browser for all websites.

  28. Debu Majumdar says

    Please explain why did you include
    Disallow: /refer/
    in the beginner Robots.txt example? I do not understand the implications of this line. Is this important for the beginner? You have explained the other two Disallowed ones.

    Thanks.

  29. harsh kumar says

    hey,,i am getting error in yoast seo regarding site map..once i click on fix it ,,,it’s coming again..my site html is not loading properly

  30. Tom says

    I’ve just been reviewing my Google Webmaster Tools account and using the Search Console, I’ve found the following:
    Page partially loaded
    Not all page resources could be loaded. This can affect how Google sees and understands your page. Fix availability problems for any resources that can affect how Google understands your page.

    This is because all CSS stylesheets associated with Plugins are disallowed by the default robots.txt.

    I understand good reasons why I shouldn’t just make this allowable, but what would be an alternative as I would suspect the Google algorithms are marking down the site for not seeing these.

  31. Suren says

    Hi,

    Whenever, I search my site on the google this text appears below the link: ”A description for this result is not available because of this site’s robots.txt”

    How, can i solve this issue?

    Regards

    • WPBeginner Support says

      Hi Suren,

      Seems like someone accidentally changed your site’s privacy settings. Go to Settings » Reading page and scroll down to ’Search engine visibility’ section. Make sure that the box next to is unchecked.

      Administratör

  32. Divyesh says

    Hello

    As i seen in webmaster tool, i got robot.txt file like below :

    User-agent: *
    Disallow: /wp-admin/
    Allow: /wp-admin/admin-ajax.php

    let me know is that okey ? or should i use any other ?

  33. John Cester says

    I want to know, does it a good idea to block (disallow) ”/wp-content/plugins/” in robots.tx? Every time i remove a plugin it shows 404 error in some pages of that plugin.

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.