To prevent Google from indexing a page and request that it doesn't follow the links on that page, you can configure your Apache .htaccess file to send an X-Robots-Tag HTTP response header. The directive is X-Robots-Tag: noindex, nofollow. This method works for HTML pages and non-HTML resources such as PDFs, images, and documents. However, Google must be able to crawl the URL to read the directive.
What Does .htaccess Do for Google Noindex and Nofollow?
The .htaccess file is a configuration file used by Apache web servers. It lets website owners control certain server behaviours without editing the main Apache configuration.
One useful feature is the ability to modify HTTP response headers using the Apache mod_headers module.
For SEO, this allows you to send instructions to search engine crawlers through an HTTP header called X-Robots-Tag.
For example:
X-Robots-Tag: noindex, nofollowThis contains two separate instructions:
- Noindex: Requests that Google doesn't include the page or resource in its search results.
- Nofollow: Requests that Google doesn't follow links found on that page.
Google supports both directives in the X-Robots-Tag header. The header can also be applied to resources that don't contain HTML, which makes it useful for PDFs and other downloadable files.
Understanding noindex and nofollow
Although they're often used together, noindex and nofollow solve different problems.
| Directive | What It Does |
|---|---|
noindex | Requests that Google exclude the page from search results. |
nofollow | Requests that Google not follow links on the page. |
noindex, nofollow | Combines both instructions. |
none | An alternative to noindex, nofollow. |
For example, suppose you have a website with a private preview page containing temporary content.
You might want Google to stop displaying the page in search results and avoid using its links to discover other pages.
In that situation, noindex, nofollow is appropriate.
But if you only want to remove the page from Google Search while leaving its links available for discovery, noindex alone is generally sufficient. You don't need to add nofollow automatically.
How to Add Noindex and Nofollow to .htaccess
The following instructions assume your website runs on Apache or an Apache-compatible server, and that the mod_headers module is enabled.
Step 1: Find Your .htaccess File
First, locate the .htaccess file in your website's document root.
Depending on your hosting environment, it may be located in a directory such as:
public_html/.htaccess
You can usually access it through your hosting control panel's File Manager or using an FTP client.
If you cannot see the file, enable the option to display hidden files.
Before making changes, download a backup of the existing .htaccess file.
This is especially important for WordPress websites because the file may already contain permalink, rewrite, security, and caching rules.
Step 2: Add the noindex and nofollow Directive
Open .htaccess and add this code:
<IfModule mod_headers.c>
Header set X-Robots-Tag "noindex, nofollow"
</IfModule>Save the file.
This tells Apache to add the X-Robots-Tag response header to requests handled within the configuration scope.
Important: When added to the website's root .htaccess file, this is a broad rule. It can affect HTML pages, PDFs, images, and other resources served within that scope.
Use it only when you intend to prevent all those resources from appearing in search results.
The IfModule condition prevents an error when mod_headers is unavailable, but it also means the header won't be added in that situation.
Step 3: Apply noindex and nofollow to All PDF Files
You may not want to block your entire website from search results. Perhaps you only want to prevent Google from indexing downloadable PDF documents.
In that case, use a filename-based rule:
<IfModule mod_headers.c>
<FilesMatch "(?i)\.pdf$">
Header set X-Robots-Tag "noindex, nofollow"
</FilesMatch>
</IfModule>This targets PDF files rather than every resource on the website.
For example, it can be useful for:
- Internal company documents
- Temporary PDF downloads
- Private preview documents
- Outdated downloadable resources
- Documents that shouldn't appear in Google Search
Google specifically documents using .htaccess and the X-Robots-Tag header to control indexing of PDF files.
Step 4: Apply noindex and nofollow to a Single PDF File
Suppose you have one PDF file named internal-guide.pdf that shouldn't appear in Google Search.
Instead of blocking every PDF, use:
<IfModule mod_headers.c>
<Files "internal-guide.pdf">
Header set X-Robots-Tag "noindex, nofollow"
</Files>
</IfModule>Place this .htaccess file in the directory containing the PDF.
For example:
public_html/
downloads/
.htaccess
internal-guide.pdfThe rule will apply to the matching file in that directory.
This is a better approach when you only need to exclude a particular document rather than an entire file type.
Step 5: Apply noindex and nofollow to a Specific URL
What happens when you want to block a single URL rather than a physical file?
For example:
https://example.com/preview-page/
A website may generate this page dynamically through PHP, WordPress, or another CMS. In that situation, matching the filename with a Files directive may not be suitable.
Apache's mod_setenvif module can identify a request using its URL path.
Add this to your root .htaccess file:
<IfModule mod_setenvif.c>
SetEnvIf Request_URI "^/preview-page/?$" noindex_target
</IfModule>
<IfModule mod_headers.c>
Header set X-Robots-Tag "noindex, nofollow" env=noindex_target
</IfModule>Replace /preview-page/ with the path of your actual page.
The regular expression matches both:
/preview-page/preview-page/
The first directive identifies matching requests. The second adds the HTTP header only when the environment variable noindex_target is present.
Apache documents both SetEnvIf and conditional response headers in its server configuration documentation.
This approach requires both mod_setenvif and mod_headers to be available.
For CMS installations with complex routing, test the response carefully to make sure the rule matches the public URL you intended.
How to Apply Noindex Without Nofollow
Sometimes you want a page removed from Google but don't want to request that Google ignore its links.
For this situation, use:
<IfModule mod_headers.c>
Header set X-Robots-Tag "noindex"
</IfModule>This sends only the noindex instruction.
You can also use the same technique with a PDF file:
<IfModule mod_headers.c>
<FilesMatch "(?i)\.pdf$">
Header set X-Robots-Tag "noindex"
</FilesMatch>
</IfModule>This prevents matching PDF resources from appearing in Google Search while omitting the additional nofollow instruction.
Remember that Google doesn't require you to explicitly specify index, follow for pages you want indexed. These are the default behaviours.
.htaccess vs. Robots.txt vs. Meta Robots Tag
These three methods are often confused because they're all related to search engine crawling and indexing.
However, they serve different purposes.
| Method | Main Purpose | Where It Is Configured |
|---|---|---|
.htaccess with X-Robots-Tag | Control indexing through HTTP response headers | Apache configuration |
robots.txt | Control crawler access to URL paths | Root robots.txt file |
| Meta robots tag | Control indexing instructions for an HTML page | HTML document |
1. .htaccess with X-Robots-Tag
Use this method when you want to control indexing through HTTP response headers.
It is particularly useful for files such as PDFs, images, and other non-HTML resources.
It can also apply rules to multiple pages or resources using Apache configuration.
2. Robots.txt
A robots.txt file tells compatible crawlers which URL paths they are allowed to crawl.
For example:
User-agent: Googlebot
Disallow: /private/This requests that Googlebot not crawl URLs under /private/.
However, robots.txt is not a reliable method for removing a URL from Google Search results.
If Google cannot crawl a page, it may not be able to discover the noindex instruction in its response. A URL can sometimes remain indexed based on information from other pages linking to it.
Use robots.txt when your objective is to manage crawling, not when your primary objective is to deindex an accessible URL.
3. Meta Robots Tag
If you only need to control one standard HTML page, a meta robots tag may be easier than changing .htaccess.
Add the following inside your HTML document:
<meta name="robots" content="noindex, nofollow">For example:
<!DOCTYPE html>
<html>
<head>
<title>Private Preview Page</title>
<meta name="robots" content="noindex, nofollow">
</head>
<body>
<h1>Private Preview</h1>
</body>
</html>Google supports the meta robots tag and the X-Robots-Tag header for the same indexing instructions. You can choose the method that fits your website and content type.
Which Method Should You Choose?
Your choice depends on what you're trying to accomplish.
| Your Requirement | Recommended Method |
|---|---|
| Remove one HTML page from Google | Meta robots noindex |
| Remove a PDF from Google | .htaccess with X-Robots-Tag |
| Remove every PDF from Google | .htaccess with FilesMatch |
| Remove a specific dynamically generated URL | Conditional X-Robots-Tag |
| Prevent crawling of a URL path | robots.txt |
| Keep confidential content inaccessible to visitors | Authentication or access restrictions |
Important: Does Nofollow Completely Stop Google from Following Links?
No. This is one of the most important distinctions to understand.
Google changed how it handles nofollow in 2019, with the change taking effect for crawling and indexing purposes on March 1, 2020.
Google now treats nofollow as a hint rather than an absolute instruction that it must always follow.
This means Google may choose to use other information and signals when deciding whether to crawl or discover a URL.
So, adding the following header:
Header set X-Robots-Tag "nofollow"doesn't guarantee that Google will never discover or crawl links on the page.
If you want a page excluded from Google Search, use noindex, not nofollow alone.
Page-Level Nofollow vs. Link-Level Nofollow
There is another distinction worth understanding.
Page-level nofollow:
<meta name="robots" content="nofollow">This applies to links on the entire page.
Link-level nofollow:
<a href="https://example.com" rel="nofollow">Example</a>This applies to a particular link.
The same concept applies when using an HTTP header. A page-level X-Robots-Tag: nofollow is different from adding rel="nofollow" to individual links.
Choose the method that matches your actual SEO requirement.
How to Check Whether Google Noindex Is Working
Adding code to .htaccess doesn't automatically mean the directive is working.
The important thing is whether the correct HTTP response header is actually being sent to crawlers.
You can check this in two ways.
Method 1: Check the HTTP Response Header
Use a browser-based HTTP header checker or run this command in your terminal:
curl -s -D - -o /dev/null https://example.com/preview-page/Replace the example URL with your actual page.
Look for this response header:
X-Robots-Tag: noindex, nofollowIf you see it, the server is sending the expected directive.
If it is missing, check:
- Whether the
.htaccessfile is in the correct directory. - Whether the server supports
.htaccess. - Whether
mod_headersis enabled. - Whether the hosting configuration allows the
Headerdirective. - Whether another server or application configuration is overriding the header.
Also check the public response rather than relying only on the contents of the configuration file.
Method 2: Use Google Search Console
Google Search Console provides a more useful way to verify what Google can actually access.
Follow these steps:
- Open Google Search Console.
- Select your website property.
- Enter the page URL in the URL Inspection tool.
- Select Test Live URL.
- Review the page's indexing information and test results.
- Check whether indexing is allowed or blocked by a
noindexdirective.
Google's URL Inspection tool can also show the HTTP response headers and raw HTML returned during a live test.
The Page Indexing report can help you check indexing status in Search Console for URLs where Google has detected a noindex instruction.
How Long Does Google Take to Remove a Noindex Page?
Adding a noindex directive doesn't immediately remove an already indexed URL.
Google needs to crawl the URL again, discover the instruction, and process the change.
The timing depends on when Google revisits the page. Google explains that, depending on a page's importance and crawling frequency, detecting a newly added noindex rule can sometimes take months.
You can use the URL Inspection tool to request a recrawl, although this doesn't guarantee immediate removal.
For urgent removal from Google Search, the Removals tool can temporarily hide an eligible URL while the permanent indexing instruction is processed.
The distinction is important:
- Noindex: A permanent indexing instruction while it remains in place and is accessible to Google.
- Removals tool: A temporary search-result removal mechanism.
- Robots.txt: A crawling restriction, not a permanent deindexing instruction.
For permanent exclusion, make sure Google can access the page and read its noindex directive.
Common .htaccess Noindex and Nofollow Mistakes
Even a small configuration mistake can make your indexing instructions ineffective.
Here are some problems worth checking before publishing changes.
1. Blocking the Page in robots.txt
One common mistake is using both:
Disallow: /preview-page/in robots.txt and:
Header set X-Robots-Tag "noindex"in .htaccess.
The problem is that Google may be unable to crawl the page and discover the noindex header.
For deindexing, make sure Googlebot can crawl the URL until it has processed the instruction (see our full guide on how to deindex a site from Google).
2. Applying noindex to the Entire Website Accidentally
Adding the following rule to your root .htaccess file can affect more than the page you intended:
Header set X-Robots-Tag "noindex, nofollow"It may also affect your important landing pages, blog posts, downloadable files, and other website resources.
Before applying a site-wide rule, confirm that you genuinely want all those URLs excluded from search results.
3. Using .htaccess on an Nginx Server
Nginx doesn't use Apache .htaccess files.
If your website runs directly on Nginx, the server administrator must configure the header using Nginx configuration instead.
For example:
location = /preview-page/ {
add_header X-Robots-Tag "noindex, nofollow";
}Google documents both Apache and Nginx approaches for X-Robots-Tag.
4. Assuming noindex Protects Private Information
A noindex directive doesn't make a page private.
Visitors can still open the URL directly, and other websites may link to it.
If a page contains confidential business information, customer records, private downloads, or sensitive documents, use authentication or server-level access restrictions.
Don't rely on search engine directives as a security mechanism.
5. Forgetting to Check Other SEO Settings
A website may have more than one source of indexing instructions.
For example, WordPress, an SEO plugin, server configuration, a CDN, or your application may add other robots directives.
Check the actual HTTP response and rendered HTML for duplicate or conflicting rules.
Google generally applies the more restrictive instruction when it encounters conflicting robots rules, but it's better to remove unnecessary conflicts rather than rely on them.
What to Do After Removing a Noindex Directive
Sometimes you add noindex during development, testing, or a temporary content restriction and later decide that the page should appear in Google.
In that case, removing the directive is only the first step.
Check the following:
- Remove the
noindexinstruction from.htaccess, your meta robots tag, or any other source generating it. - Confirm that
robots.txt(check or build yours with our robots.txt generator) doesn't prevent Googlebot from crawling the page. - Check that the page returns an appropriate successful HTTP response.
- Test the live URL in Google Search Console.
- Make sure the page is included in your XML sitemap when appropriate.
- Request indexing through URL Inspection if a recrawl is needed.
You should also verify that no other part of your website is adding a noindex directive.
For websites managing many URLs, an automated submission and monitoring workflow can help organize indexing activities after the technical restrictions have been resolved. InstantIndexer, for example, provides automated URL submission and Google and Bing indexing monitoring (see how an instant indexing tool handles removals). However, submitting a URL cannot override a noindex directive that tells Google not to index it. You can also build valid Apache header rules cleanly with our free .htaccess generator.
Choose the Right Noindex and Nofollow Configuration
Using .htaccess for Google noindex and nofollow is a practical way to control search engine indexing through HTTP response headers.
The best configuration depends on the scope of your requirement.
For one HTML page, a meta robots tag is often simpler. For PDFs and other non-HTML resources, X-Robots-Tag is more suitable. For several files or specific URL paths, Apache configuration gives you more control.
Most importantly, don't confuse crawling restrictions with indexing instructions. Keep URLs accessible to Google when you need it to read a noindex directive, verify the actual response header, and use authentication whenever content needs to remain private.
A correctly scoped rule can prevent unwanted pages and resources from appearing in Google without accidentally excluding your entire website.
Frequently Asked Questions
1. What is the .htaccess code for Google noindex and nofollow?
Use this Apache configuration:
<IfModule mod_headers.c>
Header set X-Robots-Tag "noindex, nofollow"
</IfModule>It sends an HTTP response header requesting that Google not index the resource or follow the links on the page. Make sure the rule is applied only to the URLs you intend to exclude.
2. Can I use .htaccess to noindex only one page?
Yes. You can use a conditional SetEnvIf rule based on Request_URI and add the X-Robots-Tag header only when the requested URL matches. This is useful for dynamically generated pages that don't correspond directly to a physical HTML file.
3. Should I use noindex or noindex, nofollow?
Use noindex when your main goal is to prevent a page from appearing in Google Search. Use noindex, nofollow when you also want to request that Google not follow links on that page. The additional nofollow instruction isn't required for deindexing.
4. Can Google still index a page blocked by robots.txt?
Yes, in some situations. Google may discover a URL through external or internal links and include it in search results without crawling its content. This is why robots.txt isn't the recommended method for permanent removal from Google Search. Use a crawlable noindex directive instead.
5. Does noindex, nofollow work for PDF files?
Yes. Google supports the X-Robots-Tag response header for non-HTML resources, including PDFs. You can configure Apache to apply this instruction to every PDF file or to an individual document using Files or FilesMatch rules.
6. How can I confirm that Google has detected the noindex header?
First, check the HTTP response using a tool such as curl and confirm that X-Robots-Tag: noindex is present. Then use Google Search Console's URL Inspection tool and Page Indexing report to check whether Google has detected the directive.
7. Does noindex remove a page immediately from Google?
No. Google needs to recrawl the URL and process the noindex instruction. You can request a recrawl through Google Search Console, but there is no guaranteed immediate removal time.
8. Does .htaccess noindex block visitors from accessing a page?
No. The directive controls search engine indexing, not visitor access. Anyone who knows the URL may still be able to visit it. Use password protection, authentication, or appropriate server permissions when you need to restrict access.



