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]

Why does the first block of directives not work and why does it only work when it's part of the WordPress directives?

1 Answer 1


When 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.


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.

  • Thanks for the clarification. To be clear, is WordPress routing requests to index.php because the page thanks is physically non-existent?
    – Motivated
    Commented Sep 18, 2019 at 17:55
  • Yes, the page exists within WordPress, not as a physical HTML file on the filesystem.
    – MrWhite
    Commented Sep 18, 2019 at 20:57
  • Thanks. Is there any reason as to why headers such as X-Robots-Tag would not work similarly? I posted another question since it results in a different behavior - wordpress.stackexchange.com/questions/348557/…
    – Motivated
    Commented Sep 19, 2019 at 8:29
  • "...why headers such as X-Robots-Tag would not work similarly?" - I wouldn't say that was "similar"... I've answered your other question....
    – MrWhite
    Commented Sep 26, 2019 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.