Marroiak
Marroiak

Reputation: 81

Joomla htaccess mobile redirect

I have 2 versions of a website, desk and mobile:

  1. www.olivashot.com
  2. www.mobile.olivashot.com

My htacces is redirecting mobile devices to the mobile version.

The problem...

1- If a visitor comes from google beacause he has searched "thing" and the full link it´s shown as "www.olivashot.com/index.php/thing" it redirects to "www.mobile.olivashot.com/index.php/thing" (I have a happy visitor)

2- But if the link in google is: "www.olivashot.com/thing" >>> he is redirected to "www.mobile.olivashot.com" (I´m loosing a visitor beacuse I´m not showing what he expected)

I thing this is beause I´m rewriting "something" to quit the default "index.php" in joomla site

RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script

RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.




RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://www.mobile.olivashot.com/$1/ [R=301,L]

Upvotes: 0

Views: 1494

Answers (1)

Riccardo Zorn
Riccardo Zorn

Reputation: 5615

You should put the last block before the Joomla custom redirect which has some exit points. This means the order should be:

RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://www.mobile.olivashot.com/$1/ [R=301,L]


## Begin - Joomla! core SEF Section.
...

You can drop the line RewriteEngine On it's already enabled at the top of the file. For added security once you get this working you can check out the boilerplate template's .htaccess file, h5bp.com

Upvotes: 2

Related Questions