Search code examples
wordpress.htaccessurl-rewritinggoogle-search-consoleclean-urls

Rewrite infected url by .htaccess


one of my WordPress sites was broken and thousands of URLs were added (regularly registered on Google Searc Console). Now I have removed the infection and I would like to remove all the URLs created by Google Search by creating a rule that returns a 404 error for each URL. Currently the URLs are of this type: https://example.com/?c=brine-shrimp-eggs-xx-vV63wku6 being thousands I cannot write thousands of lines but since they all started with /?c= I was thinking of something like

RedirectMatch 404 ^/?c=*/.*$

I've tryed but no results


Solution

  • You need to use the rewriting module, it is more flexible than the alias module. Something like that:

    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^c=
    RewriteRule ^ - [R=404,L]
    

    You can implement such rule in the central http hosts configuration. Or, if you do not have access to that you can also use a distributed configuration file (typically called ".htaccess"), if you enabled such files beforehand using the AllowOverride directive for that location inside your http host.