Redirect URL to 410 error with complex wildcard

I have an SEO issue as google has indexed thousands of links (the site was hacked) which are now directed to 404 errors. I need to change these to 410 errors so Google then considers the pages deleted.

All hacked pages follow a system wherby they begin with a letter ‘g’ followed by either a 3, 4 or 5 digit number eg:, or Is there a method using a wildcard to redirect these errors to my 410 page? I’m guessing this is a regex that need to be added to my htaccess file.


Firstly, you don’t redirect to 410, but you do give a 410 header, uisng G (gone).

RewriteEngine on #if not already
RewriteRule ^g[0-9]{3,5}\/$ - [G,L]

To see how the regex ^g[0-9]{3,5}\/$ works, paste it in here.
The L is to say it’s the last rule (if it is to be).

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.