Apache/2.2.9, RH Enterprise, mod_rewrite, RewriteRule not working as expected

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I am having some difficulties with the Rewrites in my apache config.
I've been at this for a couple of weeks now and I admit I am having a
very difficult time with the syntax.  I've read the mod_rewrite
documentation as well as the URL rewriting guide, but nothing I try
seems to be working.  I am now behind in my project so I caved and need
to reach out to the pros for help =) 

I've searched the mailing list archives but can't seem to find my exact
situation.  I have a web site - www.example.com.  I am trying to
configure my apache to redirect all mobile users to m.example.com.  I
can get that part of it to work easily.  However, the problem is that
there are about a hundred subdirectories under www.example.com and for
mobile users I need to redirect them to the same subdirectory on
m.example.com. I would prefer not to have to write out a RewriteRule for
each subdirectory because we are constantly adding more every day and
maintenance is a bear.

Objective:
requests for www.example.com get redirected to http://m.example.com
requests for www.example.com/abc gets redirected to
http://m.example.com/abc
requests for www.example.com/def/index.html gets redirected to
http://m.example.com/def/index.html

The following is in my httpd.conf (I came across this suggestion based
on one of my google search):
   #Redirect Mobile users by exclusion
   RewriteCond %{HTTP_USER_AGENT}  !^.*Linux.*$ [NC]
   RewriteCond %{HTTP_USER_AGENT}  !^.*Win.*$ [NC,OR]
   RewriteCond %{HTTP_USER_AGENT}  ^.*Windows\s+CE.*$ [NC]
   RewriteCond %{HTTP_USER_AGENT}  !^.*OS\s+(X|9).*$ [NC]
   RewriteCond %{HTTP_USER_AGENT}  !^.*Solaris.*$ [NC]
   RewriteCond %{HTTP_USER_AGENT}  !^.*BSD.*$ 
   RewriteRule ^/$ http://m.example.com/ [R]

My site by default always looks for index.html.  So this works great -
requests for www.example.com/index.html are properly forwarded to the
VirtualHost I have set up for m.example.com and it services the mobile
version of index.html that I have there.  Now I needed to modify the
Rewrite rule to tackle the subdirectories.

Based on my internet searches I've tried to change my RewriteRule to the
following:
   RewriteRule ^/(.*) http://m.example.com/$1 
This actually does redirect to the same subdirectory on the mobile
Virtual Host, so I believe I got at least half of it right.  I requested
www.example.com/abc and was properly redirected to m.example.com/abc.
However, it is taking  ALL requests to www.example.com and forwards it
to m.example.com... even the non-mobile users.  This is confusing me
greatly since the RewriteCond by exclusion worked fine before - it
appears that suddenly the condition tests are failing.

Any advice/help anyone can offer is greatly appreciated.  Thanks in
advance!
 
Denise Mangano



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux