0

Possible Duplicate:
How to rewrite to mobile.myUrl.com if user is mobile? (use Apache or inside Webapp?)

Hi there! I'm trying to write a rewrite rule, that would redirect every address in my domain, to index.php, like this:

RewriteCond %{REQUEST_URI} !=/index.php RewriteRule .* /index.php

The problem with this code is that in index.php I check whether user came to my website from a pc, or a mobile device, and according to that I redirect him to appropriate version (index.html, or mobi.html) - now since this rule applies I'm stuck in a redirection loop. Pls help stackoverflowers :).

Community
  • 1
  • 1
marek
  • 249
  • 8
  • 19
  • This would be more elegantly solvable in a server side language like PHP, because you will have to maintain a list of user agents that is likely to grow over time. E.g.: http://stackoverflow.com/questions/4117555/simplest-way-to-detect-a-mobile-device – Pekka Feb 28 '11 at 15:13
  • But I know how to detect mobile device - and I'm doing it in php. I use this rewrite condition because of situation like this: www.my-web-site.com/atricle/id – marek Feb 28 '11 at 15:22
  • what does that have to do with detecting movile devices then? I don't understand. – Pekka Feb 28 '11 at 15:29
  • Nothing - I just gave an example for my usage case of this. In sum: I want to redirect every address in my domain to index.php, but when I'm doing this (from inside of index.php in m _domain): header('Location: mydomain.com/index.html'); I don't want this rule to apply - is it possible? – marek Feb 28 '11 at 15:36

1 Answers1

0

Either you just exclude the pages index.html and mobi.html:

RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !=/index.html
RewriteCond %{REQUEST_URI} !=/mobi.html
RewriteRule .* /index.php

or you can set a GET variable in your redirected url, like header('Location: domain.com/index.html?norewrite'); and then do not rewrite the URL if it contains this variable:

RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{QUERY_STRING} !^(.*&)?norewrite(&.*)?$
RewriteRule .* /index.php
Floern
  • 31,495
  • 23
  • 98
  • 115