htaccess rewrite for author query string when WP is in subfolder

Question

I have successfully forbidden access to any kind of author pages whether trough /author/username/ or the ?author={#id} query string.

I did this with this added to the beginning of my htaccess file:

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_URI} ^/author/
    RewriteRule .* - [F]
    RewriteCond %{QUERY_STRING} ^author=([0-9]*)
    RewriteRule .* - [F]
</IfModule>

But the same doesn’t work when wordpress is physically in a subdirectory.

The first part works:

RewriteCond %{REQUEST_URI} ^/subdir/author/
RewriteRule .* - [F]

But no matter how I try to edit the second part, the /subdir/?author=1 takes me to the /subdir/usernumber1/ and that is forbidden alright, but this defeats the whole purpose of this.

Any ideas?

Edit:

Yes, I was trying to prevent user names from showing.

In the last moment yesterday I was able to come up with a solution:

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_URI} ^/subdir/author/
    RewriteRule .* - [F]
    RewriteCond %{REQUEST_URI} ^/subdir/
    RewriteCond %{QUERY_STRING} ^author=([0-9]*)
    RewriteRule .* - [F]
</IfModule>

I may be able to shorten it based on the answers below(for which I’m very thankful).

And yes this is placed in the subdir.

The first snippet was placed in the root dir, which did not worked(or maybe some of the solutions that I tried along the way actually worked but I had the redirect to the author page already cached, I don’t know for sure).

0
, , D. Dan 1 year 2020-07-14T10:10:59-05:00 0 Answers 61 views 0

Leave an answer

Browse
Browse