Apache rewrite_mod: RewriteRule path and query string
Posted
by 1ace
on Stack Overflow
See other posts from Stack Overflow
or by 1ace
Published on 2010-05-10T13:44:54Z
Indexed on
2010/05/10
14:04 UTC
Read the original article
Hit count: 258
I currently have a website with a standard web interface on index.php
, and I made an iPhone-friendly version in iphone.php
.
Both pages handle the same arguments.
It works fine when I manually go to .../iphone.php
, but I'd like to rewrite anything on .../path/
and .../path/index.php
to iphone.php
if %{HTTP_USER_AGENT}
contains mobile
, and optionally add the query string (not sure if/when I'd need to add it).
So far, this is what I have in my .../path/.htaccess
:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^.+mobile.+$ [NC]
RewriteRule index.php?(.*) iphone.php?$1 [L]
RewriteRule index.php iphone.php [L]
The problems are, it matches index.php
in any subfolder, and it won't match .../path/?args
…
Special thanks to anyone who can correct/simplify/optimize anything =)
© Stack Overflow or respective owner