X Robots Tag noindex specific page

I have a Privacy Policy page on my website www.domain / privacy-policy / that I would like to do with noindex with the X Robots tag. I tried the following code but it does not match

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

## Redirect HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteRule ^privacy-policy - [env=NOINDEXFOLLOW:true]
Header set X-Robots-Tag "noindex, follow" env=NOINDEXFOLLOW

</IfModule>

# END WordPress

The question has been edited to include the full htaccess file for clarity.

+1
source share
1 answer

www.domain/privacy-policy/

The "privacy policy" is in the URL path, not in the query string, as you used in your directive. Instead, try something like the following: near the top of your file .htaccess:

RewriteEngine On
RewriteRule ^privacy-policy - [env=NOINDEXFOLLOW:true]

Header set X-Robots-Tag "noindex, follow" env=NOINDEXFOLLOW

However, it would be preferable to use mod_setenvif instead of mod_rewrite to set the environment variable:

SetEnvIf Request_URI "^/privacy-policy" NOINDEXFOLLOW

UPDATE:. front-controller ( WordPress), RewriteRule .htaccess, WP. WP, . ( SetEnvIf Header , .)

, - index.php, NOINDEXFOLLOW , . index.php Apache REDIRECT_NOINDEXFOLLOW (REDIRECT_ ), , Header. , :

SetEnvIf Request_URI "^/privacy-policy" NOINDEXFOLLOW
Header set X-Robots-Tag "noindex, follow" env=REDIRECT_NOINDEXFOLLOW

( .)

RewriteRule , NOINDEXFOLLOW, .

+1

Source: https://habr.com/ru/post/1694806/


All Articles