| myst |
|
|---|
In this article, we explain how to set up a robots.txt file in Shopware 6 on Hypernode to optimize the indexing of your webshop by search engines.
A robots.txt file allows you to instruct search engine crawlers on which parts of your website they are allowed or not allowed to index. This helps prevent duplicate content, saves additional resources, and results in more efficient indexing and better SEO performance.
Create a new text file named robots.txt and place this file in the public directory of your Shopware 6 installation. You can insert the example text below into this file:
User-agent: *
Allow: /
Disallow: */?
Disallow: */account/
Disallow: */checkout/
Disallow: */widgets/
Disallow: */navigation/
Disallow: */bundles/
Disallow: */imprint$
Disallow: */privacy$
Disallow: */gtc$
Sitemap: https://YOUR_DOMAIN/sitemap.xml
Adjust the Sitemap rule with the exact URL to your sitemap.
Use the robots.txt tester in Google Search Console to verify if the configuration is correct and the desired pages are being blocked or allowed.
In the root of your Shopware 6 installation, navigate to the public directory. Create a new folder called robots:
mkdir public/robotsWithin the newly created robots directory, create a separate robots.txt file for each domain. For example:
public/robots/www.example.com.txtpublic/robots/shop.example.com.txt
Each file should contain the rules specific to the corresponding domain. Below is an example for www.example.com:
User-agent: *
Allow: /
Disallow: */?
Disallow: */account/
Disallow: */checkout/
Disallow: */widgets/
Disallow: */navigation/
Disallow: */bundles/
Disallow: */imprint$
Disallow: */privacy$
Disallow: */gtc$
Sitemap: https://www.example.com/sitemap.xml
Adjust the Sitemap URL and other rules according to the specific requirements of each domain.
Edit or create a new NGINX configuration file at /data/web/nginx/server.robots and add the following rewrite rule:
rewrite ^/robots\.txt$ /robots/$host.txt;This rule ensures that requests to /robots.txt are dynamically redirected to the correct file based on the domain making the request.