Apache Rewrite specific subdomains


We have a website that has been listed on Google with the original holding domains (stage, prod, etc)

We need to return a 410 to google and other bots for specific subdomains, but also rewrite other sub-domains to www (excluding other specifics, such as careers., covid. and contact.

Does this look correct (if we get it wrong then we risk getting de-listed from Google!)

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(dev|stage|prod). [NC]
RewriteCond %{HTTP_USER_AGENT} Googlebot|Baidu|Bingbot|DuckDuckBot|Slurp|Yandex [NC]
RewriteRule (.*) - [R=410,L]

RewriteCond %{HTTP_HOST} !^(www|careers|covid|contact). [NC]
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule (.*) https://www.mydomain.co.uk%{REQUEST_URI} [L,NE,R=301]

Many thanks

user190527 4 months 0 Answers 61 views 0

Leave an answer