Adding a robots.txt
file to a static website is a straightforward process. This file helps guide search engine crawlers on which parts of your site should be indexed. Here’s how you can create and add one to your PHP-based static website.
Step 1: Create the robots.txt
File
Create a new file named robots.txt
in the root directory of your website.
Step 2: Define the Rules for Crawlers
Open robots.txt
in a text editor and add the rules. Here is an example of a basic robots.txt
file:
Step 3: Upload the robots.txt
File
Upload the robots.txt
file to the root directory of your website using an FTP client or your web hosting control panel.
Step 4: Verify the robots.txt
File
Visit https://yourwebsite.com/robots.txt
in your browser to ensure it’s accessible and displays the correct rules.
Step 5: Test with Google Search Console
- Go to Google Search Console.
- Select your website.
- Navigate to Crawl > robots.txt Tester.
- Ensure your
robots.txt
file is correct and functional.
Conclusion
Adding a robots.txt
file to your static PHP website helps control which parts of your site are crawled by search engines, improving your SEO and protecting sensitive areas of your site. Follow these steps to create and verify your robots.txt
file, ensuring it’s correctly guiding search engine crawlers.