WordPress.org

Support

Support » How-To and Troubleshooting » How to 404 URLs with Query Strings Using Htaccess?

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:

    http://www.fakesite.com/page/3/?spam 301s to http://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!

Viewing 1 replies (of 1 total)
  • FYI, I tried the following:

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

    This sends the bad URLs to the default WordPress 404 page, but the server returns a 302 found response. That’s not quite right. Anyone know how to solve this?

    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘How to 404 URLs with Query Strings Using Htaccess?’ is closed to new replies.