Mike George
Mike George

Reputation: 521

htaccess redirect to mobile website. Keep the same trailing path

I have my website automtically redirecting to a mobile version if the user has an iphone or ipod with .htaccess. But I would like to keep the same link structure.

For example: http://www.domain.com/status/?variable=12345678

Currently redirects to: http://iphone.domain.com/

The end of the link is lost. So in the end I would like it to keep the end of the url and go to

http://iphone.domain.com/status/?variable=12345678

Upvotes: 0

Views: 935

Answers (1)

Andrew
Andrew

Reputation: 946

Something along the lines of

RewriteCond %{HTTP_HOST} ^www.domain.com
RewriteRule ^(.*)$ http://iphone.domain.com/$1

should work. The $1 is the key.

This will take http://www.domain.com/your-exact-path

and change it to http://iphone.domain.com/your-exact-path

You will of course still need to determine whether the user is accessing from a phone before using this.

Upvotes: 1

Related Questions