I couldn’t find any straightforward super-fast solution online so, this is mine.
It will take you:
- 1 actual line of code
- 1 minute
It assumes that :
- Your WordPress website is hosted on an Apache server
- Your Apache server supports
- You have full access to
It will let you redirect users to the home page in case they try to access a category / tag / author page.
Step by Step
- Connect via FTP to your web server.
- Download the
.htaccessfile at the root of your WordPress installation (usually
- Open the file for edition.
- Copy-Paste this block at the beginning of the file :
5. Save, close and upload the file to your web server.
How it works
Should you have 1 minute to dig a little bit into a short explanation, this is the right place.
Line 1 and 4 :Tells Apache to execute the block only if the
mod_rewritemodule is present.
Line 2 :Tells Apache to activate the Rewrite Engine. This engine can rewrite URLs on the go.
Line 3 :We define a rule following this common syntax :
RewriteRule patternToMatchAgainst whereToRedirect [Options]
^(author|tag|category)\/.+$: This is the pattern to match against.
If you’re not familiar with regular expressions, take a look to this article
This pattern means : If the request looks like
/category/anything then, redirect somewhere.
/: This is the place we redirect the user in case the pattern is matched. It is the root of your WordPress website. It means that if someone tries to navigate to a category / tag / author page, he will be redirected to the home page.
Thanks for reading
I hope this short tutorial has been helpful to you and solved this common need.
Running my own WordPress website, I prefer having almost no plugin installed and that’s why configuring Apache seemed to be the way to go.
Check out my latest tutorial :
Feel free to reach out at email@example.com
Fullstack Developer, Trainer & Entrepreneur.
Learning stuff, sharing knowledge and building on top of great ideas are my top priorities.