admin管理员组文章数量:1318319
I want to block all access to the post/tag/example-here
pages on a WordPress site, but the following does not work. The .htaccess
access file is being parsed. It is at the root of the site (ie the public_html
) on a regular cPanel account. I've tried with and without the leading slash. I don't understand why it wouldn't be working.
RewriteCond %{REQUEST_URI} ^post/tag/
RewriteRule .* - [F]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I want to block all access to the post/tag/example-here
pages on a WordPress site, but the following does not work. The .htaccess
access file is being parsed. It is at the root of the site (ie the public_html
) on a regular cPanel account. I've tried with and without the leading slash. I don't understand why it wouldn't be working.
RewriteCond %{REQUEST_URI} ^post/tag/
RewriteRule .* - [F]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Share
Improve this question
edited Oct 21, 2020 at 1:02
MrWhite
3,8911 gold badge20 silver badges23 bronze badges
asked Oct 20, 2020 at 23:00
jamesgarrettjamesgarrett
1433 bronze badges
0
1 Answer
Reset to default 2RewriteCond %{REQUEST_URI} ^post/tag/ RewriteRule .* - [F]
The REQUEST_URI
server var does start with a slash (it is a full root-relative URL-path), although you do say you have tried this "with and without the leading slash", so this should have worked if that is what you are referring to and /post
is the first path-segment in the URL-path.
However, you don't need the additional RewriteCond
directive here as the URL check can (and should) be performed in the RewriteRule
directive instead. For example:
RewriteRule ^post/tag/ - [F]
In this case, there is no slash prefix on the RewriteRule
pattern.
If that is still failing then try matching against THE_REQUEST
instead, which contains the first line of the request headers and is not modified by other rewrites (unlike REQUEST_URI
and the URL-path matched by the RewriteRule
directive).
For example:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/post/tag/
RewriteRule ^ - [F]
THE_REQUEST
would contain a string of the form:
GET /post/tag/example-here HTTP/1.1
Still not working... then make sure you don't have a custom 403 ErrorDocument
that is routing the request through WordPress. If you have not defined anything yourself, then this could still be defined in the server config (by your host), which you can reset to the Apache default with the following in .htaccess
:
ErrorDocument 403 default
本文标签: mod rewriteblocking access to all posttag URIs via htaccess
版权声明:本文标题:mod rewrite - blocking access to all posttag URIs via htaccess 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742046387a2417810.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论