You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在WordPress的.htaccess中用X-Robot-Tag设置查询串页面为noindex

How to Set Noindex for WooCommerce Layered Navigation Filter Pages via .htaccess

Hey there! Let's tackle this noindex issue for your WooCommerce layered navigation filter pages. Since you're already using Yoast for most pages but those dynamic filter results are slipping through, using .htaccess with X-Robot-Tag is a solid approach—here's how to do it step by step:

Step 1: Identify Your Filter Page URL Pattern

First, pin down the common pattern of your filter pages. WooCommerce's default layered nav typically uses query parameters starting with filter_ (like filter_color=blue or filter_size=large). If your pages follow this structure, the rule below will work perfectly. If they use a different pattern (e.g., a specific URL path like /shop/filter-*), you can tweak the matching rule later.

Step 2: Add the Rule to Your .htaccess File

Open your site's root .htaccess file (usually in the same folder as your WordPress wp-config.php), and add this code before the default WordPress rewrite rules (the section starting with # BEGIN WordPress):

# Target WooCommerce layered navigation filter pages
<IfModule mod_headers.c>
    # Match URLs containing filter_ query parameters (adjust if your params are different)
    RewriteCond %{QUERY_STRING} filter_ [NC]
    RewriteRule ^ - [ENV=NOINDEX:true]

    # Apply X-Robots-Tag header to matched pages
    Header set X-Robots-Tag "noindex, follow" env=NOINDEX
</IfModule>

What Each Part Does:

  • <IfModule mod_headers.c>: Ensures your server supports the mod_headers module (most mainstream hosts enable this by default, but adding this prevents errors if it's not available).
  • RewriteCond %{QUERY_STRING} filter_ [NC]: Matches any URL with a query parameter starting with filter_ (the [NC] flag makes the match case-insensitive).
  • RewriteRule ^ - [ENV=NOINDEX:true]: Sets an environment variable NOINDEX to true for all matching pages.
  • Header set X-Robots-Tag "noindex, follow" env=NOINDEX: Adds the X-Robots-Tag header with noindex, follow only when the NOINDEX environment variable exists. Use "noindex, nofollow" instead if you don't want crawlers to follow links on these pages.

Step 3: Adjust for Custom URL Patterns

If your filter pages use a specific URL path instead of query parameters (e.g., /shop/filter-red-blue/), replace the RewriteCond line with this:

RewriteCond %{REQUEST_URI} ^/shop/filter- [NC]

Modify the path (^/shop/filter-) to match your actual filter page structure.

Important Notes

  • Backup First: Always make a copy of your .htaccess file before editing it—if something goes wrong, you can restore the original quickly.
  • Test the Rule: Open one of your filter pages, then use your browser's developer tools (go to the Network tab, reload the page, and check the response headers) to confirm the X-Robots-Tag: noindex, follow is present.
  • Avoid Yoast Conflicts: Double-check that Yoast isn't setting an index tag for these pages. You can exclude filter pages from Yoast's index settings, or verify Yoast's meta tags don't override the .htaccess header (server-level headers usually take priority, but it's good to confirm).

内容的提问来源于stack exchange,提问作者SupGen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:02:24