Skip to content

Instantly share code, notes, and snippets.

@RichardBronosky
Created August 24, 2011 21:37
Show Gist options
  • Select an option

  • Save RichardBronosky/1169318 to your computer and use it in GitHub Desktop.

Select an option

Save RichardBronosky/1169318 to your computer and use it in GitHub Desktop.
[CMSMI-190] Redirect non-mobile-ready content types to www.
<Directory /services/django>
Options FollowSymLinks
</Directory>
Alias /media "/services/django/vm/storyville/vm/media/"
<Location "/media">
SetHandler None
Order allow,deny
allow from all
</Location>
<Location "/admin/media">
SetHandler None
Order allow,deny
allow from all
</Location>
# Jira CMSAP-260 10/01/2010
Alias /shared/static "/services/django/vm/storyville/vm/media/static"
Alias /shared/media "/services/django/vm/storyville/vm/media/shared/media/"
<Location "/admin/">
Allow from All
# Order Deny,Allow
# Deny from All
# Allow from 169.137. 66.6.145.128/25 216.27.162.123/32 66.6.146.58/32 10.216.32.0/24 66.6 10.216.33.0/24 10.188.10.0/24 10.155.90.0/24 10.150.44.1/22 10.155.48.1/22
# Allow from 169.137. 66.6.145.128/25 216.27.162.123/32 66.6.146.58/32 10.216.32.0/24 66.6. 10.216.33.0/24 10.188.10.0/24
</Location>
ServerAdmin [email protected]
AddType image/x-icon .ico
RewriteEngine On
# Define the MOBILE_PATTERN (for user agent detection) ONLY for pages who are NOT black listed from mobile. (TODO: Try using a whitelist instead. Would probably be shorter.)
RewriteCond %{REQUEST_URI} !^/(ads|alerts|answers|audioclips|bands|categories|categories|events|documents|drinkspecials|events|features|forums|gallery|instruments|maps|mp3|lsp|onthestreet|photo|photos|galleries|photos|places|playlists|podcasts|polls|pr|qa|questionnaires|recipes|restaurants|restaurants|specials|search|songs|special_coverage|staff|stories|traffic|tumble|videos) [NC]
RewriteRule .* - [E=MOBILE_PATTERN:iphone|ipod|android|blackberry|symbian|nokia|sonyericsson|sie-|opera\ mini|portalmmm/|windows\ ce|up.browser|up.link|802sh|alcatel-|amoi-|attws|au-mic|audiovox|avantgo|benq|cdm-|ericsson|ericy-|gs308|hitachi-p300|htc-|i-2100|inn|kwc-|lg-|lg/u|lge-|lge/u|lowestcd|mo0|mobilephone|mot-|motorola|n5-10|nec-|opwv|owg1|palm|panasonic|pg-c|philips|pls|pm-|pn-215|profile/midp|qci-|rl-|rpt-httpclient|sagem|samsung|sanyo|sch-a|sch-n|scp-|sec-|sendox|sgh|sharp|smartphone|spha|v60t|vi600|vk530|vm4050|vodafone|wapper|wildseed|winwap-pro]
# NOTICE: The RewriteCond pattern below must be kept exactly in sync with the definition of MOBILE_PATTERN in the RewriteRule above. Make all changes in both places.
# Detect mobile agents and bare domains. Set a redirect flag if found. Flag will be used a few block below
RewriteCond %{HTTP_USER_AGENT} iphone|ipod|android|blackberry|symbian|nokia|sonyericsson|sie-|opera\ mini|portalmmm/|windows\ ce|up.browser|up.link|802sh|alcatel-|amoi-|attws|au-mic|audiovox|avantgo|benq|cdm-|ericsson|ericy-|gs308|hitachi-p300|htc-|i-2100|inn|kwc-|lg-|lg/u|lge-|lge/u|lowestcd|mo0|mobilephone|mot-|motorola|n5-10|nec-|opwv|owg1|palm|panasonic|pg-c|philips|pls|pm-|pn-215|profile/midp|qci-|rl-|rpt-httpclient|sagem|samsung|sanyo|sch-a|sch-n|scp-|sec-|sendox|sgh|sharp|smartphone|spha|v60t|vi600|vk530|vm4050|vodafone|wapper|wildseed|winwap-pro [NC]
RewriteCond %{HTTP_HOST} "!^(m|www)\..+" [NC]
RewriteRule .* - [E=REDIRECT_MOBILE:1]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule .*favicon\.ico$ /media/multi/static/favicon.ico [L]
# Jira SUPPORT-116 11/16/2010
RewriteRule robots.txt$ /media/vm/static/robots.txt
RewriteRule crossdomain.xml$ /media/vm/static/crossdomain.xml
# Rule to redirect /_svc/np.xml to new location /lsp/xml/i
# on all sites except boortz and clark
RewriteCond %{HTTP_HOST} !^.*clarkhoward.*$
RewriteCond %{HTTP_HOST} !^.*boortz.*$
RewriteRule .*_svc/np.xml$ /lsp/xml/ [PT]
# Redirect non-mobile-ready content types to www. domain.
RewriteCond %{HTTP_HOST} !^www\..+ [NC]
RewriteCond %{ENV:MOBILE_PATTERN} !.+
RewriteCond %{HTTP_HOST} ^(m\.)?(.*)$
# The following Rule relies on the previous Cond to provide an "m." stripped HTTP_HOST in variable %2
RewriteRule /(.*) http://www.%2/$1 [R=302,L]
# NOTICE: the following 2 blocks contain FEATURE SWITCHES
# A. Allows m. access to only select domains. All others get redirected to www.
# B. Enables mobile detection and redirection for bare domain requests for only select domains. All others get redirected to www.
# FEATURE SWITCH A
# This entire code block provides FEATURE SWITCH A. Removing it allows access to m. domains
RewriteCond %{HTTP_HOST} ^m\..+ [NC]
RewriteCond %{HTTP_HOST} "!(clarkhoward|power953)" [NC]
RewriteCond %{HTTP_HOST} ^(m\.)?(.*)$
# The following Rule relies on the previous Cond to provide an "m." stripped HTTP_HOST in variable %2
RewriteRule /(.*) http://www.%2/$1 [R=302,L]
# Redirect to m. if previously detected
RewriteCond %{ENV:REDIRECT_MOBILE} "1"
RewriteCond %{ENV:MOBILE_PATTERN} .+
# FEATURE SWITCH B
# The following line provides FEATURE SWITCH B. Removing it enables mobile redirection for all properties.
RewriteCond %{HTTP_HOST} "clarkhoward|power953" [NC]
RewriteRule (.*) http://m.%{HTTP_HOST}$1 [R=302,L]
# Redirect to www. if missing valid subdomain and not previously redirected
RewriteCond %{HTTP_HOST} "!^(m|www|signin)\..+" [NC]
RewriteRule (.*) http://www.%{HTTP_HOST}$1 [R=302,L]
#RewriteEngine on
## Need to redirect vmxx.(mobile|web).site.com to (mobile|web).vmxx.site.com
#RewriteCond %{HTTP_HOST} ^vm[0-9]+\.[^.]+\.[^.]+\....$
#RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
#RewriteRule ^([^.]+)\.([^.]+)\.([^.]+\...)(.*)$ http://$2.$1.$3$4 [R]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment