Skip to content

Instantly share code, notes, and snippets.

@coderjun
Created July 24, 2014 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderjun/9cea388a11b6704e308f to your computer and use it in GitHub Desktop.
Save coderjun/9cea388a11b6704e308f to your computer and use it in GitHub Desktop.
Apache mod_rewrite - IP Multicast to Unicast Fallback
### Redirect to Unicast Live
### ========================
# Without case sensitivity rewrite requests with the following formats: /videoPlayer /videoPlayer/ /videoPlayer/{filename}.html
RewriteCond %{REQUEST_URI} ^/videoPlayer(/*|.*html)$ [NC]
# AND Without case sensitivity ignore requests with a URL that contains a query string that has src=rtmp://{whatever}/vod/{whatever}
RewriteCond %{QUERY_STRING} !src=rtmp://.*/vod/.* [NC]
# AND Make sure that the client is from the 10.1.10.x or 10.1.11.x subnet
RewriteCond %{REMOTE_ADDR} ^10\.1\.1[0-1].*$
# AND disregard the clients that have already gone through the rewrite process
RewriteCond %{QUERY_STRING} !src=rtmp://.*/live/livestream
# If all conditions are met rewrite the URL to point to Unicast live stream and stop further processing
RewriteRule (.*) http://%{HTTP_HOST}/videoPlayer/index.html?src=rtmp://%{HTTP_HOST}/live/livestream [L]
### Redirect to Multicast
### ========================
# Without case sensitivity rewrite requests with the following formats: /videoPlayer /videoPlayer/ /videoPlayer/{filename}.html
RewriteCond %{REQUEST_URI} ^/videoPlayer(/*|.*html)$ [NC]
# AND Without case sensitivity ignore requests with a URL that contains a query string that has src=rtmp://{whatever}/vod/{whatever}
RewriteCond %{QUERY_STRING} !src=rtmp://.*/vod/.* [NC]
# AND Make sure that the client is NOT from the 10.1.10.x or 10.1.11.x subnet
RewriteCond %{REMOTE_ADDR} !^10\.1\.1[0-1].*$
# AND disregard the clients that have already gone through the rewrite process
RewriteCond %{QUERY_STRING} !src=assets/livestream_ip_multicast_manifest.f4m
# If all conditions are met rewrite the URL to point to the Multicast F4M live stream and stop further processing
RewriteRule (.*) http://%{HTTP_HOST}/videoPlayer/index.html?src=assets/livestream_ip_multicast_manifest.f4m [L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment