I’m creating a static webpage solution for my angularJS project where I check for the HTTP_USER_AGENT in my .htaccess file and then redirect any crawlers to a static php page so I can add all the necessary meta data.
The problem is that I’m using a wildcard subdomain, so any of my clients can have their own subdomain and I can’t figure out how to redirect via RewriteRule to the right url.
My RewriteCondlooks like this:
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9]|Facebot|Twitterbot|Pinterest|Google.*snippet)
and my basic non-working RewriteRule looks like this:
RewriteRule ^stuff/(.*)$ http://example.com/static.php?token=$1 [NC,L]
But I want it to go to static.php on that subdomain the request is on, so if I request http://subdomain.example.com/stuff?token=my-token
is it possible to make the rewriterule go to http://subdomain.example.com/static.php?token=$1
instead of just the static mydomain.com above? (there will NEVER be a request on http://example.com/stuff - all requests to stuff will be via a subdomain)
I’m not that experienced in .htaccess and get’s a bit confused from all the answer that here listed at SO and Google finds.
Edited
I found the solution by piecing some code together and getting my head around it.
My three lines of .htaccess codes that works looks like this:
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9]|Facebot|Twitterbot|Pinterest|Google.*snippet)
RewriteCond %{HTTP_HOST} ^(.+?)\.example\.com$
RewriteRule ^s/(.*)$ http://%1.sociuu.com/static.php?token=$1 [NC,L]