How to 404 URLs with Query Strings Using Htaccess?
-
Does anyone know how to redirect URLs with specific query strings (spam) to the default WordPress 404 page, using .htaccess?
I’ve currently got such parameters 301 redirecting to the original page in .htaccess, using the following code.
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)spamword1 [NC,OR]
RewriteCond %{QUERY_STRING} (^|&)spamword2 [NC,OR]
RewriteCond %{QUERY_STRING} (^|&)spamword3 [NC]RewriteRule (.*) /$1? [R=301,L]
For example:
https://www.fakesite.com/page/3/?spam 301s to https://www.fakesite.com/page/3/
This is generally OK, but Google sees it as a “soft 404” error.
I’d rather just have these URLs 404 and fall out of the index.
Any help is greatly appreciated!
- The topic ‘How to 404 URLs with Query Strings Using Htaccess?’ is closed to new replies.