0

I've an condition for my .htaccess for crawlers and search engines which takes them to a "static" page where they can scrape all content.

Up until now I've had my domain {client}.realdomain.com where {client} is a subdomain for one client.

When the client then shares something on a social network, e.g. facebook/linkedin their crawlers are taken to my .htaccess which have following conditions (and this works)

URL example: http://{client}.realdomain.com/s/token

RewriteCond %{HTTP_USER_AGENT} (LinkedInBot/[0-9]|facebookexternalhit/[0-9]|Facebot|Twitterbot|twitterbot|Pinterest|pinterest|Google.*snippet|baiduspider|rogerbot|embedly|quora\ link\ preview|showyoubot|outbrain|slackbot|vkShare|W3C_Validator)
RewriteCond %{HTTP_HOST} ^(.+?)\.realdomain\.com$
RewriteRule ^s/(.*)$ http://%1.realdomain.com/static.php?token=$1 [NC,L]

will end up as http://{client}.realdomain.com/static.php?token=token

As said, anything here works perfect but now I'm moving into having different domains, so it can be

{client}.real-domain.com and {client}.sunset.com

I essentially what the same thing in my .htaccess but it should take the whole domain with it when it redirects so it will go to e.g. http://{client}.sunset.com?static.php=token=my-secret-token if a crawler comes to {client}.sunset.com/s/my-secret-token

How would I got about doing this? I seem to be a simple solution but for some reason I just can't seem to get my head around it.

Thanks

Emil Devantie Brockdorff
  • 4,724
  • 12
  • 59
  • 76

1 Answers1

1
RewriteCond %{HTTP_USER_AGENT} (LinkedInBot/[0-9]|facebookexternalhit/[0-9]|Facebot|Twitterbot|twitterbot|Pinterest|pinterest|Google.*snippet|baiduspider|rogerbot|embedly|quora\ link\ preview|showyoubot|outbrain|slackbot|vkShare|W3C_Validator)
RewriteCond %{HTTP_HOST} ^(.+?)\.%{HTTP_HOST}%\.com$
RewriteRule ^s/(.*)$ http://%1.%{HTTP_HOST}%.com/static.php?token=$1 [NC,L]

Can you test this out? By replacing your domain name with %{HTTP_HOST}%

Diogo Jesus
  • 318
  • 4
  • 19
  • Thanks for your answer. I actually solved it just now and it seemed that it was even easier than I thought. By removing the second rewriteCond and just replace my RewriteRule with `RewriteRule ^s/(.*)$ http://%{HTTP_HOST}/static.php?token=$1 [NC,L]` and everything seem to be in order – Emil Devantie Brockdorff Mar 06 '18 at 13:54
  • glad you fixed it @Mestika – Diogo Jesus Mar 06 '18 at 13:56