hphp/runtime/server/request-uri.cpp
/**
 * Precondition: m_rewrittenURL is set
 * Postcondition: Output is true and m_path and m_absolutePath are set OR
 *   output is false and no file was found
 */
m_rewrittenURL is set
Postcondition: Output is true and m_path and m_absolutePath are set OR
output is false and no file was found
m_rewrittenURL is set Postcondition : Output is true and m_path and m_absolutePath are set OR output is false and no file was found
bool RequestURI::resolveURL(const VirtualHost *vhost,
                            const std::string &pathTranslation,
                            const std::string &sourceRoot) {
  String startURL;
  if (m_rewritten) {
    startURL = m_rewrittenURL;
  } else {
    startURL = m_originalURL;
  }
  startURL = String(
      Util::canonicalize(startURL.c_str(), startURL.size(), false),
      AttachString);
  m_resolvedURL = startURL;
  while (!virtualFileExists(vhost, sourceRoot, pathTranslation,
                            m_resolvedURL)) {
    int pos = m_resolvedURL.rfind('/');
    if (pos <= 0) {
      m_resolvedURL = startURL;
      if (!m_resolvedURL.empty() &&
          m_resolvedURL.charAt(m_resolvedURL.length() - 1) != '/') {
        m_resolvedURL += "/";
      }
      m_resolvedURL += String(RuntimeOption::DefaultDocument);
      m_origPathInfo.reset();
      if (virtualFileExists(vhost, sourceRoot, pathTranslation,
                            m_resolvedURL)) {
        m_defaultDoc = true;
        return true;
      }
      return false;
    }
    m_resolvedURL = startURL.substr(0, pos);
    m_origPathInfo = startURL.substr(pos);
  }
  if (!m_resolvedURL.empty() &&
      m_resolvedURL.charAt(0) != '/') {
    m_resolvedURL = "/" + m_resolvedURL;
  }
  if (!m_originalURL.empty() &&
      m_originalURL.charAt(0) != '/') {
    m_originalURL = "/" + m_originalURL;
  }
  m_pathInfo = String(
      Util::canonicalize(m_origPathInfo.c_str(), m_origPathInfo.size()),
      AttachString);
  return true;
}
bool RequestURI :: resolveURL ( const VirtualHost * vhost , const std :: string & pathTranslation , const std :: string & sourceRoot ) { String startURL ; if ( m_rewritten ) { startURL = m_rewrittenURL ; } else { startURL = m_originalURL ; } startURL = String ( Util :: canonicalize ( startURL . c_str ( ) , startURL . size ( ) , false ) , AttachString ) ; m_resolvedURL = startURL ; while ( ! virtualFileExists ( vhost , sourceRoot , pathTranslation , m_resolvedURL ) ) { int pos = m_resolvedURL . rfind ( ' ' ) ; if ( pos <= 0 ) { m_resolvedURL = startURL ; if ( ! m_resolvedURL . empty ( ) && m_resolvedURL . charAt ( m_resolvedURL . length ( ) - 1 ) != ' ' ) { m_resolvedURL += " " ; } m_resolvedURL += String ( RuntimeOption :: DefaultDocument ) ; m_origPathInfo . reset ( ) ; if ( virtualFileExists ( vhost , sourceRoot , pathTranslation , m_resolvedURL ) ) { m_defaultDoc = true ; return true ; } return false ; } m_resolvedURL = startURL . substr ( 0 , pos ) ; m_origPathInfo = startURL . substr ( pos ) ; } if ( ! m_resolvedURL . empty ( ) && m_resolvedURL . charAt ( 0 ) != ' ' ) { m_resolvedURL = " " + m_resolvedURL ; } if ( ! m_originalURL . empty ( ) && m_originalURL . charAt ( 0 ) != ' ' ) { m_originalURL = " " + m_originalURL ; } m_pathInfo = String ( Util :: canonicalize ( m_origPathInfo . c_str ( ) , m_origPathInfo . size ( ) ) , AttachString ) ; return true ; }
Precondition: m_rewrittenURL is set
 Postcondition: Output is true and m_path and m_absolutePath are set OR
   output is false and no file was found
Precondition : m_rewrittenURL is set Postcondition : Output is true and m_path and m_absolutePath are set OR output is false and no file was found
// when none of the <subpath> exists, we give up, and try default doc