There are at aleast two ways you can block other user agents and allow only a few. This can be done by editing the .htaccess file in the root directory of your WordPress website.
Option 1
Using mod_rewrite, add the code below at the top of your .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !(Google|Bing)
RewriteRule ^(sitemap_index\.xml)$ - [F,L]
</IfModule>
Option 2
This option uses the mod_setenvif module with SetEnvIfNoCase block incase mod_rewrite isn’t available.
Add the code below at the top of your .htaccess file.
<IfModule mod_setenvif.c>
SetEnvIfNoCase User-Agent .*google.* allowed_user_agents
SetEnvIfNoCase User-Agent .*bing.* allowed_user_agents
Order Allow,Deny
<FilesMatch "^(sitemap_index\.xml)$">
Deny from all
Allow from env=allowed_user_agents
</FilesMatch>
</IfModule>
You could also use robots.txt file, but I haven’t tested this one yet.
Related Posts:
- Improve wordpress security by hiding non public resources
- htaccess rewrite conflict with wordpress rules and ssl
- adding rewrite rules in .htaccess
- Plugin to edit htaccess file
- Serve apache 404 for missing assets rather then wp 404 template WP_Rewrites
- Remove year and month in URL using .htaccess
- Permalinks not working on second wordpress installed in a subdirect
- Unable to access WP admin
- Move wordpress to folder without changing urls
- Change wp-content without changing the name of the folder
- Using WordPress only for the backend, and using AngularJS as a frontend
- How to restrict access to wp-content, wp-includes and all sub-folders
- Two domains on one WordPress Installation
- Protect Upload Folder Files With Ampersand Problem
- Is it possible to dynamically redirect URL using htaccess?
- Which WordPress scripts need to be executable for a fresh installation?
- .htaccess and WordPress Admin Bar
- Keep getting 401 error from WordPress on AWS Lightsail
- Blocking access to wp-login via htaccess not working
- Setup Permanent 301 Redirects after moving to Https [closed]
- Force www to non-www on a subdomain in WordPress?
- How to Redirect huge numbers of URLs to another URLs?
- WP site URL changed to have HTTPS but still homepage does not redirect
- Struggling with add_rewrite_rule
- Giving WordPress its own subdirectory – nginx
- Cannot mask WordPress page URL using .htaccess
- need a help for modify .htaccess rule [closed]
- How can I make an htaccess file on a Mac? [closed]
- Restricting user login by IP address
- .htaccess ‘down for maitenance’ and WordPress
- WordPress overrides custom 404 page with it’s own
- Which is better: 301 Redirect in my .htaccess file or a plugin like Redirection?
- New installation can’t be found due to htaccess of the original non-WordPress site
- When is it necessary to have Header unset Vary in .htaccess
- Redirect http to https does not work on subdir where another instance of WordPress installed
- Fixing custom 404 pages broken by WordPress in a subdirectory
- redirect the homepage using .htaccess outside of WordPress
- I can’t access the admin panel links as I click it shows 403 error
- Https Redirect infinite loop in Mobile browsers
- 403 error on admin login page
- How to hide login form if basic authentication fails?
- Redirect an old link to new site homepage [closed]
- .htaccess rewriting old RSS feed URL to WordPress feed URL
- How can I set Cache TTL for woff and woff2 font files with htaccess?
- WordPress – Promoting A Dev Build In A Subdirectory To Production / Root Directory
- How can I fix the redirect chain after implementing ssl on wordpress?
- How do I configure wordpress structure for development using git and composer
- .htaccess RewriteRule always overwritten – how to prevent?
- How to create a redirect in the .htaccess file, with 2 exceptions
- Redirect old domain with query paramaters
- What might be removing my redirects from my htaccess?
- My Homepage Suddenly Disappeared and I Can’t Get It Back
- How to turn this .htaccess rule into a dynamic rule with add_rewrite_rule, et al?
- WordPress .htaccess to consider blog as directory
- Disable directory browsing of uploads folder
- Local PC cache stays filled with old WordPress Site data
- Password protect directory but not files
- How to have a custom URI path for specific page template
- WordPress JSON API restrict to specific domain
- Where to put W3 Total Cache rewrite rules in .htaccess? [closed]
- fix 302 redirection error on https
- main-domain of wordpress keep redirecting to subdomain
- How to deny access to a particular wordpress site url
- Rewrite Rules not redirecting rewrite
- How do i allow access to a single file in my root directory? [closed]
- Rewrite URL in address bar for a specific page [closed]
- Home links redirects to old site
- Selectively Disabling PHP via .htaccess in Root Directory
- What’s the best way to manage a lot of 301 redirects in WordPress?
- Shared hosting, multiple sites, can’t log in to WP due to .htaccess redirection
- What causes 404 errors that forces you to rebuild a .htaccess file?
- Configure .htaccess to have a WordPress single site installation with all subdomains pointing to the same pages?
- Rewriting subfolders to specific parent folder in WordPress
- Azure WordPress deny access to xmlrpc
- Xampp is not loading media
- PHP application in sub directory keeps redirecting to main site
- domain redirection is not working from old to new
- Deny,Allow on .htaccess isn’t working
- execute cron jobs when .htaccess login protected?
- Using htaccess to prevent spam through wp-comments-post.php
- Install second wordpress in root subfolder, Error 404
- change URIs of migrated site
- Remove subdirectory from links
- modifying htaccess for localhost with a custom port
- htaccess- to hide subdirectory slug only from the post
- .htaccess redirects for posts in new directory and new domain
- Steps for WordPress over SSL
- Fixing Access-Control-Allow-Origin (CORS origin) for multiple subdomains
- domain.in/wp-admin give the result to 403 Access to this resource on the server is denied!
- insert_with_markers() WordPress & htaccess help
- Restrict Content for only Contributors via .htaccess
- Redirect from domain.com to subdomain.domain.com
- MAMP.app & .htaccess – Can’t override after config
- register_post_type and register taxonomy and htaccess
- Cannot find webarh/malware redirect infection that only shows on Chrome
- Why ‘Authorization Required’ is coming on wordpress login
- Restricting direct downloads of wp content files, but allow them on the website.
- Forward blog requests to another URL
- .htaccess rewrite rule stopped working for wordpress site after moving server
- .htaccess seems to be required but I can not find it