HELP AND TIP ABOUT my code

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 2
Joined: 25 Mar 2013, 05:36

HELP AND TIP ABOUT my code

25 Mar 2013, 05:37

I have this HTACCESS file that we wrote and we need a bit help with several things

what it does is get to the demo.co.il website, redirect to www.demo.co.il

if it is a mobile or android it will go to m.demo.co.il

we have added now cookie check for full site but it works only for the homepage, the rest will loop or just redirect to 404.

1 more thing is that i'm sure there is a way to make the code shorter with conditions but i weren't able to make it work

# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.79

RewriteEngine on
RewriteBase /

RewriteRule ^(.*)mobile/$ http://m.demo.co.il/contact [QSA,R=301,NC,L]

#---------------- Redirect from regular site when agent is cellular to cellular page (friendly)
RewriteCond %{HTTP_HOST} ^demo\.co\.il$ [NC]
RewriteCond %{HTTP_USER_AGENT} !(Mobile|Android) [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http://www.demo.co.il%1%2 [NE,O,R=301,L]

RewriteCond %{HTTP_HOST} ^demo\.co\.il$ [NC]
RewriteCond %{HTTP_USER_AGENT} (Mobile|Android) [NC]
RewriteCond %{HTTP_COOKIE} ^.*fullsite.*$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http://www.demo.co.il%2 [NE,O,R=301,L]

RewriteCond %{HTTP_HOST} ^demo\.co\.il$ [NC]
RewriteCond %{HTTP_USER_AGENT} (Mobile|Android) [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteCond %{HTTP_COOKIE} !^.*fullsite.*$ [NC]
RewriteRule .? http://m.demo.co.il%2 [NE,O,R=301,L]

RewriteCond %{HTTP_HOST} ^www\.demo\.co\.il$ [NC]
RewriteCond %{HTTP_USER_AGENT} (Mobile|Android) [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteCond %{HTTP_COOKIE} !^.*fullsite.*$ [NC]
RewriteRule .? http://m.demo.co.il%2 [NE,O,R=301,L]


#---------------- Redirect to mobile page when agent is cellular (no friendly)

RewriteCond %{HTTP_HOST} ^www\.demo\.co\.il$ [NC]
RewriteCond %{HTTP_USER_AGENT} (Mobile|Android) [NC]
RewriteCond %{HTTP_COOKIE} !^.*fullsite.*$ [NC]
RewriteRule ^(.*)/showpage\.asp$ http://m.demo.co.il/$1/mobileshowpage.asp [R=301,NC,L]

RewriteCond %{HTTP_HOST} ^www\.demo\.co\.il$ [NC]
RewriteCond %{HTTP_USER_AGENT} (Mobile|Android) [NC]
RewriteCond %{HTTP_COOKIE} ^.*fullsite.*$ [NC]
RewriteRule ^(.*)/mobileshowpage\.asp$ http://www.demo.co.il/$1/showpage.asp [R=301,NC,L]

#---------------- Redirect for Friendly
RewriteCond %{HTTP_HOST} ^www\.demo\.co\.il$ [NC]
RewriteMap map2 txt:userdata/mapfile2.txt [NC]
RewriteMap map-reverse2 txt:userdata/mapfile-reverse2.txt [NC]

RewriteCond %{HTTP_HOST} ^www\.demo\.co\.il$ [NC]
RewriteCond %{QUERY_STRING} (.*)
RewriteCond /$1\?%1 (.*)
RewriteCond ${map2:%2|NOT_FOUND} (.*)
RewriteCond %3 !NOT_FOUND
RewriteRule (.*) /%3? [R=301,NC,L,NS]

RewriteCond %{HTTP_HOST} ^www\.demo\.co\.il$ [NC]
RewriteCond ${map-reverse2:$1|NOT_FOUND} (.*)
RewriteCond %1 !NOT_FOUND
RewriteRule (.*) %1 [NC,L,NS]


#---------------- Show content of index file in URL
RewriteCond %{HTTP_HOST} ^www\.demo\.co\.il$ [NC]
RewriteRule ^$ /index.asp [L]


#---------------- Redirect from mobile index to regular index
RewriteCond %{HTTP_HOST} ^m\.demo\.co\.il$ [NC]
RewriteRule ^mobileindex.asp$ / [R=301,L]

#============================================================#
#-------------------------- Mobile --------------------------#
#============================================================#

#---------------- Redirect to regular page when agent is not cellular (no friendly)
#RewriteCond %{HTTP_USER_AGENT} !(Mobile|Android) [NC]
#RewriteRule ^(.*)/mobileshowpage\.asp$ http://www.demo.co.il/$1/showpage.asp [R=301,NC,L]

#---------------- Redirect from mobile site when agent is not cellular to regular page (friendly)
RewriteCond %{HTTP_HOST} m\.demo\.co\.il$ [NC]
RewriteCond %{HTTP_USER_AGENT} !(Mobile|Android) [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http://www.demo.co.il%2 [NE,O,R=301,L]


#---------------- Redirect for Friendly
RewriteCond %{HTTP_HOST} ^m\.demo\.co\.il$ [NC]
#RewriteCond %{HTTP_COOKIE} !^.*fullsite.*$ [NC]
RewriteMap map2M txt:userdata/mapfile2M.txt [NC]
RewriteMap map-reverse2M txt:userdata/mapfile-reverse2M.txt [NC]

RewriteCond %{HTTP_HOST} ^m\.demo\.co\.il$ [NC]
RewriteCond %{QUERY_STRING} (.*)
RewriteCond /$1\?%1 (.*)
RewriteCond ${map2M:%2|NOT_FOUND} (.*)
RewriteCond %3 !NOT_FOUND
#RewriteCond %{HTTP_COOKIE} !^.*fullsite.*$ [NC]
RewriteRule (.*) /%3? [R=301,NC,L,NS]

RewriteCond %{HTTP_HOST} ^m\.demo\.co\.il$ [NC]
RewriteCond ${map-reverse2M:$1|NOT_FOUND} (.*)
RewriteCond %1 !NOT_FOUND
#RewriteCond %{HTTP_COOKIE} !^.*fullsite.*$ [NC]
RewriteRule (.*) %1 [NC,L,NS]


#---------------- Show content of mobile index file in URL
RewriteCond %{HTTP_HOST} ^m\.demo\.co\.il$ [NC]
RewriteRule ^$ /mobileindex.asp [L]


#---------------- Redirect from regular index to mobile index
RewriteCond %{HTTP_HOST} ^m\.demo\.co\.il$ [NC]
RewriteRule ^index.asp$ / [R=301,L]

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: HELP AND TIP ABOUT my code

25 Mar 2013, 11:38

Hello,


Please, provide rewrite.log for a testing request.
Logging issues are described in FAQ - http://www.helicontech.com/forum/10648-FAQ.html

Regards
Andrew

User avatar
Posts: 2
Joined: 25 Mar 2013, 05:36

Re: HELP AND TIP ABOUT my code

27 Mar 2013, 01:41

On that server we have several websites. i can allow logs for so many cuase the log will be too big to be open

how do i log a specific website?

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: HELP AND TIP ABOUT my code

27 Mar 2013, 11:31

There's no way to enable logging for specific web-site. You may temporary comment out most of the rules and then see the logs.
Make sure you have loggin OFF most of the time, enable logging for debugging purposes only.

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 12 guests