WordPress.org

Ready to get started?Download WordPress

Forums

How to 404 URLs with Query Strings Using Htaccess? (2 posts)

  1. scot184
    Member
    Posted 1 year ago #

    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!

  2. scot184
    Member
    Posted 1 year ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic