0

What lines of code would I enter in the .htaccess perform the redirect only if the target is the homepage? That is the main question here. I'll elaborate:

I used the method described at: Mobile Redirect using htaccess to redirect mobile. Works great. Now, what my client is trying to do is when someone is on mobile, if they are trying to access a page that is not the homepage (i.e. a blog), then they do NOT get redirected. So, if the target is the homepage, the redirect works as normal. Make sense?

So, I'll simplify it again -- what lines of code would I enter in the .htaccess perform the redirect only if the target is the homepage?

Here is what I have (minus the detection part)

RewriteCond %{REQUEST_URI} ^/index.php$ [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
#there is a bunch of other user agents #
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST}          !^m\. 
# Can not read and write cookie in same request, must duplicate condition
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]
# Now redirect to the mobile site
RewriteRule ^ http://m.thesiteurl.com [R,L]
Community
  • 1
  • 1
hdwebpros
  • 528
  • 3
  • 7
  • 20

1 Answers1

0

These first two lines should work , replace RewriteRule as per your need .

RewriteCond %{REQUEST_URI} ^/index.php$ [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /something.php

Yes It should work like :

RewriteCond %{REQUEST_URI} ^/index.php$ [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile} !^$ 
RewriteCond %{HTTP_HOST} !^m\. 
RewriteCond %{HTTP:Cookie} !\smredir=0(;|$) 
RewriteRule ^ m.example.org%{REQUEST_URI} [R,L]
Rahul
  • 1
  • 1
  • Thanks. So before place it before this? `code` RewriteCond %{HTTP:x-wap-profile} !^$ [OR] RewriteCond %{HTTP:Profile} !^$ RewriteCond %{HTTP_HOST} !^m\. RewriteCond %{HTTP:Cookie} !\smredir=0(;|$) RewriteRule ^ http://m.example.org%{REQUEST_URI} [R,L]`code` – hdwebpros Jan 29 '13 at 16:30
  • Any help would be greatly appreciated. I'm lost on this one. Thanks, – hdwebpros Feb 18 '13 at 18:58
  • I asked the question a couple of times. No luck. http://stackoverflow.com/questions/17241204/mobile-redirection-using-htaccess-only-on-homepage – hdwebpros Jun 21 '13 at 18:18