Home > Software engineering >  Redirect paths in .htaccess AND 410 everything else
Redirect paths in .htaccess AND 410 everything else

Time:10-15

I have a list of about 15 paths that I want to permanently redirect to a new domain, including the homepage.

However, I want everything else not in this list to 410 (gone). Is this possible in .htaccess without listing all other URLs/Paths?

RewriteRule ^category1\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category2\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category3\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category4\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category5\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category6\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category7\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category8\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category9\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category10\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category11\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category12\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category13\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category14\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^category15\*$  https://NEWSITE.com/ [R=301,L]
RewriteRule ^$  https://NEWSITE.com/ [R=301,L]

CodePudding user response:

You can just add the following after the existing redirects to serve a 410 Gone for everything else:

# 401 Gone for everything else
RewriteRule . - [G]

Aside:

RewriteRule ^category1\*$  https://NEWSITE.com/ [R=301,L]

This regex does not look correct. That \* near the end of the regex is a literal *, so this only redirects /categeory1* (literal string). Is that the intention?

Maybe you mean ^category1/.*$? Which is the same as ^category1/. And matches any URL-path that starts /catgeory1/. (?)

  • Related