3

Is there anything i can use in my htaccess to send 410 code to all the links but not some links ?

Example:

I would like to 410 this urls (List is about 40k links)

www.example.com/c1
www.example.com/c2
www.example.com/c3
www.example.com/c4
www.example.com/g1
www.example.com/g2
www.example.com/g3
www.example.com/g4
and so one....

but this links should not come 410, anything that start with c or g

Like:

www.example.com/categories/
www.example.com/concreate/
www.example.com/colombs/

Right now I am using this code in my .htaccess file but this also giving 410 to above links.

RewriteEngine On
RewriteCond %{QUERY_STRING} c
RewriteRule .* - [G,L]
ErrorDocument 410 default

Any help would be much appreciated.

2 Answers 2

4
RewriteCond %{QUERY_STRING} c

Not sure why you are referencing the QUERY_STRING here? Your URLs don't appear to contain a query string?

It looks like the URLs you want to block start with a c or g and followed by a digit (I'll assume 1 or more digits). In which case, try something like the following:

RewriteEngine On
RewriteRule ^[cg]\d+$ - [G]

No need for the L flag with G.

1
  • 1
    Wow! This is exactly i was looking for from long time. I just had to add this at the bottom for perfect 410 page "ErrorDocument 410 default". You are just wonderful. Huge thanks for your help. Commented May 18, 2017 at 18:42
1

user82217 provided a fine solution using mod_rewrite. You can also use mod_alias to do it:

RedirectMatch gone "/[cg]\d+$"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.