user3355603 user3355603 - 1 month ago 16
Apache Configuration Question

Htaccess file redirect not working any more switched https virtual host

I have recently switched my site over to https using a virtual host, the bots dont seem to re-directing to the snapshot page now, the site when i got direct the url redirects to https, but my htaccess does not seem to be aware of the re-direct stup...

The re-direct to the snapshot was working preivously before the https..

RewriteCond %{HTTP_USER_AGENT} Googlebot
RewriteCond %{HTTP_HOST} https://upfrontbeats\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /snapshots/index.html [NC,L]

RewriteCond %{HTTP_USER_AGENT} facebookexternalhit/1.1|Twitterbot/1.0 [NC]
RewriteCond %{HTTP_HOST} https://upfrontbeats\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /snapshots/index.html [L,R=301]


This is bottom half still works fine its just the root url

######################################THIS NEEDS TO GO ON TOP TO STOP RE DIRECT LOOP AS IT HITS SNAP SHOT DIRECTORY
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
################################

# RewriteCond %{HTTP_USER_AGENT} Googlebot
# RewriteCond %{HTTP_HOST} upfrontbeats\.com [NC]
# RewriteCond %{QUERY_STRING} _escaped_fragment_=(.*)$
# RewriteRule ^(.*)$ /snapshots/index.html [NC,L]

RewriteCond %{HTTP_USER_AGENT} facebookexternalhit/1.1|Twitterbot/1.0 [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_=(.*)$
RewriteRule ^(.*)$ /snapshots/$1 [L,R=301]

RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=/?(.*)$
RewriteRule ^(.*)$ /snapshots/%1? [NC,L]

RewriteRule ^(.*) /index.php [NC,L]

Answer

You can only match domain name not scheme using HTTP_HOST variable.

Keep your first redirect rule like this:

RewriteCond %{HTTP_USER_AGENT} Googlebot|facebookexternalhit|Twitterbot [NC]
RewriteCond %{HTTP_HOST} upfrontbeats\.com$ [NC]
RewriteRule ^/?$ /snapshots/index.html [L,R=301]
Comments