Pages

Thursday, December 23, 2021

Prevent category browsing in Wordpress











Here's how to disable category and tag listing in WordPress using .htaccess. 

Place this at the top before # BEGIN WordPress and # BEGIN iThemes Security and other security plugins.

 
//Sat 22-Jan-22 2:04pm metadataconsulting.ca - 
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#for tags change category to tag

#catches https://yoursite.com/term/ & https://yoursite.com/term/values/...
RewriteRule ^country/(.*)$ https://yoursite.com/your/new/url [R=301,L]
RewriteRule ^state/(.*)$ https://yoursite.com/your/new/url [R=301,L]
RewriteRule ^language/(.*)$ https://yoursite.com/your/new/url [R=301,L]

#catches https://yoursite.com/term
RewriteRule ^country$ https://yoursite.com/your/new/url [R=301,L]
RewriteRule ^state$ https://yoursite.com/your/new/url [R=301,L]
RewriteRule ^language$ https://yoursite.com/your/new/url [R=301,L]

#catches https://yoursite.com/category/country/ & https://yoursite.com/category/country/values/...
RewriteRule ^category/country/(.*)$ https://yoursite.com/your/new/url [R=301,L]
RewriteRule ^category/state/(.*)$ https://yoursite.com/your/new/url [R=301,L]
RewriteRule ^category/language/(.*)$ https://yoursite.com/your/new/url [R=301,L]

#catches https://yoursite.com/category/country
RewriteRule ^category/country$ https://yoursite.com/your/new/url [R=301,L]
RewriteRule ^category/state$ https://yoursite.com/your/new/url [R=301,L]
RewriteRule ^category/language$ https://yoursite.com/your/new/url [R=301,L]

#general rule forward all categories
#RewriteRule ^category/(.*) https://yoursite.com/your/new/url [R=301,L] #this is being forwarded
</IfModule>

1 comment:

  1. "Thank you for breaking this down so well! This post is truly valuable."

    ReplyDelete