help with user agent .htaccess rewrite rule

dami99

New member
Jan 30, 2009
285
0
0
X-Com
Hi all. I'm trying to implement a redirect based on useragent, but only for a specific folder.

Example:

If the user agent "exampleuseragent" requests:

http://www.mysite.com/folder/

...it should be redirected to:

http://www.mysite.com/folder/index2.html


This is my current .htaccess file. The final 2 lines are the ones trying to make this work.

This htaccess is in the root of the site. I have also tried using a different .htaccess inside the folder, but still can't make it work. Any ideas??


Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html|php)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(html|php)$ http://www.mysite.com/$1 [R=301,L]

RewriteCond %{HTTP_USER_AGENT} exampleuseragent
RewriteRule /folder/ http://www.mysite.com/folder/index2.html [R=301,L]
 


Thanks very much - the resource looks pretty useful. Going to try various things from there, that should nail it now.
 
Hi all. I'm trying to implement a redirect based on useragent, but only for a specific folder.

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html|php)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(html|php)$ http://www.mysite.com/$1 [R=301,L]

RewriteCond %{HTTP_USER_AGENT} exampleuseragent
RewriteRule /folder/ http://www.mysite.com/folder/index2.html [R=301,L]

You almost had it.

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html|php)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(html|php)$ http://www.mysite.com/$1 [R=301,L]

RewriteCond %{HTTP_USER_AGENT} exampleuseragent
RewriteCond %{REQUEST_URI} !^/folder/index2.html [NC]
RewriteRule folder/ http://www.mysite.com/folder/index2.html [R=301,L]