最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

htaccess - Force a 403 response to xml file in Wordpress

programmeradmin5浏览0评论

I'm looking to force a 403 access denied response for an xml file in a directory outside of the default Wordpress install.

The url I'm trying to force the 403 response on looks like this mydomain/autodiscover/autodiscover.xml

I've tried modifying the default Wordpress htaccess file by adding a line to ignore the custom directory but it doesn't seem to work. When visiting the url I get a 404. I did create the directory and xml file and pushed them to our server.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(autodiscover)($|/) – [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

<Files ~ "\.(xml)$">
    deny from all
</Files>

Wondering if anyone has every run into this before and if they found a solution. My end goal would be to just force the 403 on the one file so my xml sitemaps don't get blocked as well.

Thanks in advance.

I'm looking to force a 403 access denied response for an xml file in a directory outside of the default Wordpress install.

The url I'm trying to force the 403 response on looks like this mydomain/autodiscover/autodiscover.xml

I've tried modifying the default Wordpress htaccess file by adding a line to ignore the custom directory but it doesn't seem to work. When visiting the url I get a 404. I did create the directory and xml file and pushed them to our server.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(autodiscover)($|/) – [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

<Files ~ "\.(xml)$">
    deny from all
</Files>

Wondering if anyone has every run into this before and if they found a solution. My end goal would be to just force the 403 on the one file so my xml sitemaps don't get blocked as well.

Thanks in advance.

Share Improve this question asked Jul 15, 2020 at 16:28 brandozzbrandozz 8121 gold badge14 silver badges27 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

So to restate your question you want mydomain/autodiscover/autodiscover.xml to produce a 403, and your Wordpress installation is at mydomain/ ?

Then this should do it to match that specific file only:

RewriteRule ^autodiscover/autodiscover.xml - [R=403,NC,L] 

The fix that worked was adding an htaccess file to the directory with the line below

ErrorDocument 403 default
发布评论

评论列表(0)

  1. 暂无评论