Current scenario: I have a website xyz.com. The default home page is configured as index.php currently. That is, when apache gets a HTTP GET "/" request, we serve index.php.
Requirement:
Now, I want to serve index1.php wherever the user-agent string contains "google" as the sub-string. So I wrote the following code in .htaccess:
=======================
RewriteCond %{HTTP_USER_AGENT} Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) [OR]
RewriteCond %{HTTP_USER_AGENT} Googlebot/2.1 (+http://www.google.com/bot.html) [OR]
RewriteCond %{HTTP_USER_AGENT} Googlebot/2.1 (+http://www.google.com/bot.html) [OR]
RewriteCond %{HTTP_USER_AGENT} Googlebot-Image/1.0 [OR]
RewriteCond %{HTTP_USER_AGENT} Googlebot-Video/1.0 [OR]
RewriteCond %{HTTP_USER_AGENT} Mediapartners-Google [OR]
RewriteCond %{HTTP_USER_AGENT} AdsBot-Google (+http://www.google.com/adsbot.html)
RewriteRule ^/$ /index1.php [R=301,L]
===============================
After apache restart, we could see 500 server error.
Then I used Regex to match "google" like this:
=============================
RewriteCond %{HTTP_USER_AGENT} (.*)(Google)(.*) [NC]
RewriteRule ^/$ /index1.php [R=301,L]
==============================
This time, the website came up fine. However, when i spoof as Google bot, I am still seeing index.php and not index1.php.
I strongly suspect that there is something wrong with this part :
"(.*)(Google)(.*)"
Can someone help me with the correct regex for matching the substring "google"?
Thanks in advance.