S.I.
S.I.

Reputation: 3375

Properly set redirect 410 (Gone)

One of my sites has bee hacked. After I cleaned it there are a lot of fake spam URLs in the google. Now I'm trying to set them as 410 Gone and delete them from Google Search Console as well.

What I have tried to add in .htaccess but doesn't show 410 instead is showing 404.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]



RewriteRule ^https://example.com/156224863/scojgmwtdxy-7/cv.def - [L,NC,G]                                                                                  

</IfModule>

If I add this

RewriteRule !^index\.html$  https://example.com/156224863/scojgmwtdxy-7/cv.def   [L,R=410]

it is redirecting everything. Even root domain https://example.com/ which I don't want to.

What I miss here?

Upvotes: 2

Views: 3104

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133760

I believe you should put something like this in your .htacess file. Please make sure you are clearing your browser cache before testing your URLs. Make sure you escape your HTTP_HOST(domain's name) . like \. so that regex engine treat it like a literal character.

RewriteEngine ON
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteRule ^156224863/scojgmwtdxy-7/cv\.def/?$ - [R=410,L]

EDIT: As per OP's comment, everything needs to be redirected to 401 apart from base/root url then one could try following.

RewriteEngine ON
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule ^(.*) - [R=410,L]

Upvotes: 4

Related Questions