Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 1.14 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Convert NGINX rewrite rule to PHP
  2. if ($http_host !~ "([a-zA-Z0-9.-]+).example.com(.+)") {
  3.     rewrite  ^ http://example.com/browse.php?u=http://$1$2? permanent;
  4. }
  5.        
  6. <?php
  7. function unparse_url($parsed_url) {
  8.     $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
  9.     $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
  10.     $port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
  11.     $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
  12.     $query    = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
  13.     $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
  14. }
  15. if(preg_match('/^([a-zA-Z0-9.-]+).example.com/(.+)$/', $_SERVER["SERVER_NAME"])){
  16.     unparse_url(parse_url($_SERVER["SERVER_NAME"]));
  17.     header('Location: $schemeexample.com/browse.php?u=$scheme$host$port$path$query$fragment');
  18. }
  19. else {
  20. ?>
  21. <html>
  22. **HTML CONTENT HERE**
  23.        
  24. if(preg_match('#([w.-]+).example.com(.+)#', $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'], $match)) {
  25.     header('Location: http://example.com/browse.php?u=http://'.$match[1].$match[2]);
  26.     die;
  27. }