How to Deploy Your Robots.txt File
Learn how to upload and deploy your robots.txt file to various hosting platforms and servers.
📁 FTP/SFTP Upload
The traditional method works for any hosting provider with FTP/SFTP access.
- Create your robots.txt file using our generator
- Download the file to your computer
- Connect to your server using an FTP client (FileZilla, Cyberduck, WinSCP)
- Navigate to your website's root directory (usually
public_html,www, orhttpdocs) - Upload robots.txt to the root directory
- Verify it's accessible at
yourdomain.com/robots.txt
🚀 Platform-Specific Deployment
WordPress
WordPress serves /robots.txt from the site root. Choose the approach that matches your hosting setup.
Method 1: Manual upload (cPanel, SFTP, SSH)
- Create and download your robots.txt file from our generator.
- Connect to your server with FileZilla, Cyberduck, WinSCP, or SSH using the credentials from your host.
- Upload
robots.txtto the same directory aswp-config.php(usuallypublic_htmlorwww). - Set permissions to
644(readable by everyone) and purge any caching plugins/CDN. - Verify at
https://yourdomain.com/robots.txtand submit to Google Search Console if needed.
Method 2: Yoast SEO / All in One SEO
- Install and activate your preferred SEO plugin.
- Yoast: Tools → File editor → Create robots.txt → Paste your rules → Save.
- All in One SEO: Search Appearance → Advanced → Robots.txt Editor → Enable custom robots.txt → Paste → Save Changes.
- Clear any page caching (WP Rocket, W3 Total Cache, Cloudflare) so the new file serves immediately.
Managed WordPress hosts
- WP Engine, Kinsta, Flywheel: use the built-in file manager or SSH to upload to
/www/wp-content/../robots.txt. - SiteGround / Bluehost: File Manager → public_html → Upload robots.txt.
Method 3: Theme snippet / WP-CLI (copy-ready)
Prefer to keep robots.txt versioned with your theme? Drop the snippet below into functions.php or a site-specific plugin—WordPress will render your custom rules dynamically and you never have to upload a file again.
add_filter( 'robots_txt', function ( $output, $public ) {
if ( ! $public ) {
return "User-agent: *\nDisallow: /";
}
return trim("
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://example.com/sitemap.xml
");
}, 10, 2 ); Deploy via git/CI, or run wp theme refresh / wp plugin activate your-plugin on managed hosts to publish instantly.
Shopify
- Log in to your Shopify admin
- Go to Online Store → Themes → Actions → Edit code
- Find
robots.txt.liquidin the "Templates" folder - Edit the file with your custom robots.txt content
- Save changes
⚠️ Note: Shopify automatically adds some rules. Your custom rules will be appended.
Copy-ready robots.txt.liquid starter
{% layout none %}
User-agent: *
Disallow: /checkout/
Disallow: /cart
Disallow: /admin
Disallow: /orders
Allow: /collections/
Sitemap: https://{{ shop.primary_domain.host }}/sitemap.xml
# Respect Shopify defaults
{% render 'robots', directives: 'default' %} Save, then preview at https://yourstore.com/robots.txt. Use Theme Settings → App embeds to keep the snippet under version control.
Squarespace
- In Squarespace, open Website → Settings → Developer Tools → robots.txt (Business and Commerce plans).
- Toggle Custom robots.txt, paste your rules from RobotsTxt Pro, and click Save.
- Squarespace publishes instantly—visit
https://yourdomain.com/robots.txtto confirm. - Legacy 7.0 sites: enable Developer Mode → connect via SFTP → upload robots.txt to the root directory.
- After edits, clear site cache (Settings → Advanced → Website Availability → Clear Cache) if changes do not appear right away.
ℹ️ Squarespace may serve a cached file for up to a few minutes—append ?v=1 during spot checks if needed.
Disallow: /, and leave production untouched. Vercel
- Place robots.txt in your project's
public/folder - Commit and push to your repository
- Vercel will automatically deploy it
- Accessible at
yourdomain.com/robots.txt
Next.js (self‑hosted or Vercel)
Option 1: Static file
- Add
public/robots.txtto your Next.js project. - Commit the file and redeploy—Next.js automatically serves everything in
public/from the site root. - Verify locally at
http://localhost:3000/robots.txtand again after deployment.
Option 2: Generate automatically with next-sitemap
- Install:
npm install next-sitemap --save-dev. - Create
next-sitemap.config.js:
/** next-sitemap.config.js */
module.exports = {
siteUrl: 'https://yourdomain.com',
generateRobotsTxt: true,
robotsTxtOptions: {
policies: [
{ userAgent: '*', allow: '/' },
{ userAgent: 'GPTBot', disallow: ['/internal/'] },
],
},
};- Add a script to
package.json:\"postbuild\": \"next-sitemap\". - Run
npm run buildand deploy. The generated robots.txt will live inpublic/.
Option 3: App Router dynamic endpoint
Need different rules per environment? Export a typed config from app/robots.ts—Next.js serves it as plain text automatically.
// app/robots.ts
import type { MetadataRoute } from 'next'
export default function robots(): MetadataRoute.Robots {
const isPreview = process.env.NEXT_PUBLIC_STAGE === 'preview'
return {
rules: [
{
userAgent: '*',
allow: isPreview ? [] : ['/'],
disallow: isPreview ? ['/'] : ['/api/internal', '/drafts'],
},
{ userAgent: 'GPTBot', disallow: ['/customer-data'] },
],
sitemap: [
'https://example.com/sitemap.xml',
'https://example.com/blog-sitemap.xml',
],
}
}Push to Vercel—no rewrites necessary and the endpoint stays version-controlled.
Netlify
- Place robots.txt in your project's
public/or root folder - Deploy your site (git push or drag-and-drop)
- File will be served at the root of your domain
Laravel
Option 1: Static file
- Copy robots.txt into the Laravel
public/directory. - Commit and deploy; Laravel serves everything in
public/directly. - Confirm at
https://yourdomain.com/robots.txt.
Option 2: Dynamic response
Useful when you need environment-specific rules.
// routes/web.php
Route::get('/robots.txt', function () {
$content = view('robots')->render();
return response($content, 200)
->header('Content-Type', 'text/plain');
}); Create resources/views/robots.blade.php with your rules and deploy.
// resources/views/robots.blade.php
User-agent: *
Disallow: /admin/
Disallow: /api/
@env('production')
Sitemap: https://example.com/sitemap.xml
@else
Disallow: /
@endenv Commit the Blade view so staging/production differences stay in git, then run php artisan config:cache and redeploy.
Django
- Add
robots.txtto yourstatic/directory (or the app-level static folder). - Ensure
django.contrib.staticfilesis enabled andSTATICFILES_DIRSincludes the path. - Collect static files:
python manage.py collectstaticbefore deployment.
Serve via TemplateView (ideal for dynamic rules)
# urls.py
from django.urls import path
from django.views.generic import TemplateView
urlpatterns = [
# ...
path(
"robots.txt",
TemplateView.as_view(template_name="robots.txt", content_type="text/plain"),
),
]Ruby on Rails
- Place robots.txt in the Rails
public/directory and redeploy. - Assets in
public/bypass the asset pipeline and are served directly.
Need environment-specific rules?
# config/routes.rb
Rails.application.routes.draw do
# ...
get '/robots.txt' => 'robots#index'
end
# app/controllers/robots_controller.rb
class RobotsController < ApplicationController
layout false
def index
rules = Rails.env.production? ? Rails.root.join('config/robots.prod.txt') : Rails.root.join('config/robots.dev.txt')
render plain: File.read(rules), content_type: 'text/plain'
end
endGitHub Pages
- Add robots.txt to your repository root
- Commit and push to your
gh-pagesbranch - GitHub will serve it automatically
Apache Server
- Upload robots.txt to your
public_htmlorhtdocsfolder - Ensure file permissions are set to 644 (readable by all)
- No .htaccess configuration needed
Nginx Server
- Place robots.txt in your site's root directory (e.g.,
/var/www/html) - Ensure proper permissions:
chmod 644 robots.txt - Nginx serves static files by default
✅ Verify Your Deployment
🔧 Common Issues & Troubleshooting
404 Error (File Not Found)
Ensure robots.txt is in the root directory, not in a subdirectory. It must be at yourdomain.com/robots.txt, not yourdomain.com/blog/robots.txt
File Not Updating
Clear your browser cache and CDN cache. Some hosts cache robots.txt aggressively.
Wrong File Permissions
Set permissions to 644 (readable by everyone). Use: chmod 644 robots.txt
