I'm not sure if this will work for hierarchies. Specifically, with something like: 
  http://olddomain.com/videos/6.002x/video1.mp4
  http://olddomain.com/videos/8.01x/video1.mp4

Both videos will translate to: 
  http://newdomain.com/video1.mp4

You may consider using: 
  https://docs.python.org/2/library/urlparse.html

Something like this might be more robust: 

  import urlparse
  a = list(urlparse.urlsplit("https://docs.python.org/2/library/urlparse.html"))
  a[1]="newserver.com"
  urlparse.urlunsplit(a)