0

Using: Wordpress Editing: .htaccess

Is it possible to send URLs with specific query strings (spam) to the default WordPress 404 page, using .htaccess?

I currently have 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:

http://www.mysite.com/page/3/?spam 301s to http://www.mysite.com/page/3/

But is there a way to 404 these pages instead of 301 redirecting them? Google seems to think they're soft 404s if I use 301 redirects.

And everyone always recommends 404 pages for URLs that don't technically exist.

I tried this:

RewriteEngine on
RewriteCond %{QUERY_STRING}spamword
RewriteRule (.*) /404.php? [R,L]

And it sends the pages to the default Wordpress 404 URL (which is good), but the server responds as "302 found," which I know isn't correct.

Thank you for any assistance!

Colin Rock
  • 81
  • 1
  • 1
  • 4

1 Answers1

0

this thread has more info - Redirect to Apache built-in 404 page with mod_rewrite?

basically you need to add -

<?php
header( "HTTP/1.1 404 Not Found" );
exit;
?>

in the header and it parses as a 404.

Community
  • 1
  • 1