[Cialug] Rewrite rule help

Matthew Nuzum newz at bearfruit.org
Wed Aug 10 17:57:11 CDT 2011


Thanks, Chris, for the tip about the RewriteLog. I've got LogLevel set to 3.
I'm getting this output for the url / when my desktop browser hits the
mobile site:


I didn't include that there there were two blocks of rules. The RewriteLog
shows that the first block is getting processed and the second isn't. Am I
missing something? Here are the rules, the log is below:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !ELB-HealthChecker [NC]
RewriteCond %{HTTP_HOST} !^xyz\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://xyz.com/$1 [L,R=302]

RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_ACCEPT} !"text/vnd.wap.wml|application/vnd.wap.xhtml+xml"
[NC]
RewriteCond %{HTTP_USER_AGENT}
!"acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-"
[NC]
RewriteCond %{HTTP_USER_AGENT}
!"dang|doco|erics|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-"
[NC]
RewriteCond %{HTTP_USER_AGENT}
!"maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC]
RewriteCond %{HTTP_USER_AGENT}
!"palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany"
[NC]
RewriteCond %{HTTP_USER_AGENT}
!"sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo"
[NC]
RewriteCond %{HTTP_USER_AGENT}
!"teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC]
RewriteCond %{HTTP_USER_AGENT} !"wapp|wapr|webc|winw|winw|xda|xda-" [NC]
RewriteCond %{HTTP_USER_AGENT}
!"up.browser|up.link|windowssce|iemobile|mini|mmp" [NC]
RewriteCond %{HTTP_USER_AGENT}
!"symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
#RewriteCond %{HTTP_USER_AGENT} macintosh [NC]
RewriteRule ^$ http://www.xyz.com/ [L,R=302]

LOG: (level 9)

10.245.185.231 - - [10/Aug/2011:22:52:02 +0000] [
xyz.com/sid#7f46ce1d5bd0][rid#7f46ce425448/initial] (2) init rewrite engine
with requested uri /
10.245.185.231 - - [10/Aug/2011:22:52:02 +0000] [
xyz.com/sid#7f46ce1d5bd0][rid#7f46ce425448/initial] (3) applying pattern
'^/(.*)' to uri '/'
10.245.185.231 - - [10/Aug/2011:22:52:02 +0000] [
xyz.com/sid#7f46ce1d5bd0][rid#7f46ce425448/initial] (4) RewriteCond:
input='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.1
(KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1'
pattern='!ELB-HealthChecker' [NC] => matched
10.245.185.231 - - [10/Aug/2011:22:52:02 +0000] [
xyz.com/sid#7f46ce1d5bd0][rid#7f46ce425448/initial] (4) RewriteCond: input='
xyz.com' pattern='!^xyz\.com' [NC] => not-matched
10.245.185.231 - - [10/Aug/2011:22:52:02 +0000] [
xyz.com/sid#7f46ce1d5bd0][rid#7f46ce425448/initial] (3) applying pattern
'^$' to uri '/'
10.245.185.231 - - [10/Aug/2011:22:52:02 +0000] [
xyz.com/sid#7f46ce1d5bd0][rid#7f46ce425448/initial] (1) pass through /
10.245.185.231 - - [10/Aug/2011:22:52:02 +0000] [
xyz.com/sid#7f46ce1d5bd0][rid#7f46ce42b478/subreq] (2) init rewrite engine
with requested uri /
10.245.185.231 - - [10/Aug/2011:22:52:02 +0000] [
xyz.com/sid#7f46ce1d5bd0][rid#7f46ce42b478/subreq] (1) pass through /


On Tue, Aug 9, 2011 at 1:08 PM, Matthew Nuzum <newz at bearfruit.org> wrote:

> I have this ugly rewrite rule that works to redirect mobile browsers to a
> mobile page. I tried inverting the logic and making it redirect desktop
> browsers to the non-mobile site. I thought it was working but as I moved to
> a new server it is either no longer working or it never was.
>
> This works and sends mobiles to the right place:
> RewriteCond %{REQUEST_URI} ^/$
> RewriteCond %{HTTP_USER_AGENT} !ELB-HealthChecker [NC]
> RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml"
> [NC,OR]
> RewriteCond %{HTTP_USER_AGENT}
> "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-"
> [NC,OR]
> RewriteCond %{HTTP_USER_AGENT}
> "dang|doco|erics|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-"
> [NC,OR]
> RewriteCond %{HTTP_USER_AGENT}
> "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
> RewriteCond %{HTTP_USER_AGENT}
> "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany"
> [NC,OR]
> RewriteCond %{HTTP_USER_AGENT}
> "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo"
> [NC,OR]
> RewriteCond %{HTTP_USER_AGENT}
> "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
> RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
> RewriteCond %{HTTP_USER_AGENT}
> "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
> RewriteCond %{HTTP_USER_AGENT}
> "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
> RewriteRule ^(.*)$ http://mysite.com/ [L,R=302]
>
> This isn't:
> RewriteCond %{REQUEST_URI} ^/$
> RewriteCond %{HTTP_ACCEPT}
> !"text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC]
> RewriteCond %{HTTP_USER_AGENT}
> !"acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-"
> [NC]
> RewriteCond %{HTTP_USER_AGENT}
> !"dang|doco|erics|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-"
> [NC]
> RewriteCond %{HTTP_USER_AGENT}
> !"maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC]
> RewriteCond %{HTTP_USER_AGENT}
> !"palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany"
> [NC]
> RewriteCond %{HTTP_USER_AGENT}
> !"sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo"
> [NC]
> RewriteCond %{HTTP_USER_AGENT}
> !"teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC]
> RewriteCond %{HTTP_USER_AGENT} !"wapp|wapr|webc|winw|winw|xda|xda-" [NC]
> RewriteCond %{HTTP_USER_AGENT}
> !"up.browser|up.link|windowssce|iemobile|mini|mmp" [NC]
> RewriteCond %{HTTP_USER_AGENT}
> !"symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
> RewriteRule ^(.*)$ http://www.mysite.com/ [L,R=302]
>
> Any idea what I'm missing?
>
> --
> Matthew Nuzum
> newz2000 on freenode, skype, linkedin and twitter
>
> ♫ You're never fully dressed without a smile! ♫
>
>
>


-- 
Matthew Nuzum
newz2000 on freenode, skype, linkedin and twitter

♫ You're never fully dressed without a smile! ♫
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cialug.org/pipermail/cialug/attachments/20110810/bdb2b0c3/attachment-0001.html>


More information about the Cialug mailing list