I am managing a wordpress blog and want to throw a 404 error whenever the url contains a string pattern (example: if the url contains “thisisnotwanted”). I was thinking I will be able to add something to the htaccess file like: Redirect “thisisnotwanted” 404
Can someone help? I just don’t want Google to index pages with this parameter.
If you want to disallow Google from indexing pages, you should add a
robots.txt
file to the root folder of your website.You could then put something like this in the file:
I assume you want to disallow the page from all search engines, but if you only want to disallow Google, the you should change the first line to
User-agent: Google
.You can tell Google explicitly to remove the links using Webmaster tools. It could take a few days before Google will accept your request and remove the pages from their index.
For more information, please visit this website:
The Web Robots Pages
This could be achived using robots.txt but since you’re asking how to throw the 404 page manualy here it is :
This bit of code is just an example on how you can display a 404 page, and it shouldn’t be used in “production”, instead use robots.txt as Michiel Pater sugested .
You could set a conditional statement in your theme file to redirect the viewer to the 404 page.
using this code:
Using mod_rewrite, it would be something like
in a .htaccess