The directive below is intended to block access to the thank you page. It appears below the WordPress directives. It does not work as intended in that the page remains accessible and does not display a 403
error
RewriteCond %{THE_REQUEST} ^(.*)?thanks?(/)$ [NC]
RewriteRule ^(.*)$ - [F,L]
When the directive is included as part of the WordPress directives, it works as intended.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} ^(.*)?thanks?(/)$ [NC]
RewriteRule ^(.*)$ - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Why does the first block of directives not work and why does it only work when it's part of the WordPress directives?
The directive below is intended to block access to the thank you page. It appears below the WordPress directives. It does not work as intended in that the page remains accessible and does not display a 403
error
RewriteCond %{THE_REQUEST} ^(.*)?thanks?(/)$ [NC]
RewriteRule ^(.*)$ - [F,L]
When the directive is included as part of the WordPress directives, it works as intended.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} ^(.*)?thanks?(/)$ [NC]
RewriteRule ^(.*)$ - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Why does the first block of directives not work and why does it only work when it's part of the WordPress directives?
Share Improve this question asked Sep 17, 2019 at 19:09 MotivatedMotivated 2452 silver badges11 bronze badges1 Answer
Reset to default 2When the directive is included as part of the WordPress directives
It simply needs to go before the WordPress front-controller. In fact, you should not include this as "part of the WordPress directives" as WP itself tries to maintain this block of code and could override your custom directives in a future update.
You should put this custom directive directive before the # BEGIN WordPress
block.
It does not work if you put the directives "below the WordPress directives" because it is simply never processed. The preceding WP directives route all requests (for non-existent files/directories) to /index.php
- after which processing stops and any mod_rewrite directives that follow are bypassed.
It would only work (with directives after the WP front-controller) if the "thank you" request mapped directly to a physical file on the filesystem - in which case the request is not rewritten to /index.php
and processing is allowed to continue through the file.
Aside:
RewriteCond %{REQUEST_URI} ^(.*)?thanks?(/)$ [NC] RewriteRule ^(.*)$ - [F,L]
This can be simplified to a single directive:
RewriteRule thanks?/$ - [NC,F]
The L
(last
) flag is not required when the F
flag is used; it is implied.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745151496a4613889.html
评论列表(0条)