0

I'm trying to set X-Robots-tag for some url parameters and specific path, simulatenously from htaccess.

I have google indexing urls such as

https://www.shantima.com/shop/large-waffle-linen-bath-towel/?wishlist-action
https://www.shantima.com/ru/shop/vafelnoe-lnyanoe-bannoe-polotence/?wishlist-action&lang=ru
https://www.shantima.com/ru/?taxonomy=product_shipping_class&term=0-5-1kg-ru/page/2/
https://www.shantima.com/wp-admin/admin-ajax.php?action=rest-nonce
https://www.shantima.com/ru/blog/tag/whomademyclothes/feed/

And obviously I don't like this at all... looking to set X-Robots-tag header on all of these variations of urls.

so what I currently have on my htaccess is this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} ^taxonomy=([a-zA-Z0-9]*)$ [OR]
RewriteCond %{QUERY_STRING} ^term=([a-zA-Z0-9]*)$ [OR]
RewriteCond %{QUERY_STRING} ^action=([a-zA-Z0-9]*)$ [OR]
RewriteCond %{QUERY_STRING} ^lang=([a-zA-Z0-9]*)$ [OR]
RewriteCond %{QUERY_STRING} ^wishlist-action=([a-zA-Z0-9]*)$ [OR]
Rewritecond /feed/
RewriteRule .* - [E=NOINDEX_HEADER:1] 
</IfModule>
<IfModule mod_headers.c>
Header set X-Robots-Tag "noindex" env=NOINDEX_HEADER
</IfModule>
# END WordPress

Now.. as you guessed, this is not working for non of the url variations, no queries and not the "feed" path...

Would love to have your suggestions on how to resolve this thing... Any idea how I can make this work?

Your help will be highly appreciated!

Cheers & Regards

J.o

J.o.
  • 11
  • 4
  • `Rewritecond /feed/` makes no sense - you need _two_ "parameters", one input value, and the value you want to compare it to. You would need to use the REQUEST_URI environment variable here. – CBroe Sep 01 '22 at 12:51
  • And it won't work for _anything_, of course, when you place it _after_ WP's own rewriting. Any request that does not match an existing file or folder, has already been rewritten to the index.php by the WP default block currently coming before your modifications. You need to change the order. – CBroe Sep 01 '22 at 12:52
  • And your own modifications should be outside of the `# BEGIN WordPress` / `# END WordPress` comments - WordPress will _replace_ what's between those, when you flush your permalinks. – CBroe Sep 01 '22 at 12:54
  • Hey @CBroe thanks for your notes, so in general I should copy the two last ifmodule and place it after the END WordPress? – J.o. Sep 01 '22 at 14:47
  • No, they need to go _before_ the standard WP rewrites. There should be a `# BEGIN WordPress` comment as well, you need to place it before that. – CBroe Sep 02 '22 at 05:54

0 Answers0