【发布时间】:2015-12-31 18:24:10
【问题描述】:
如果之前已经回答过这个问题,我很抱歉,但我找不到答案。我有一个 .htaccess,RewriteEngine On 并且其中是规则:
RewriteEngine on
RewriteRule ^(.*) public/$1 [L]
我想在我的 app.yaml 的处理程序中调用的 mod_rewrite.php 中解释此规则
mod_rewrite.php:
<?php
/**
* @file
* Provide basic mod_rewrite like functionality.
*
* Pass through requests for root php files and forward all other requests to
* index.php with $_GET['q'] equal to path. The following are examples that
* demonstrate how a request using mod_rewrite.php will appear to a PHP script.
*
* - /install.php: install.php
* - /update.php?op=info: update.php?op=info
* - /foo/bar: index.php?q=/foo/bar
* - /: index.php?q=/
*/
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
// Provide mod_rewrite like functionality. If a php file in the root directory
// is explicitly requested then load the file, otherwise load index.php and
// set get variable 'q' to $_SERVER['REQUEST_URI'].
if (dirname($path) == '/' && pathinfo($path, PATHINFO_EXTENSION) == 'php') {
$file = pathinfo($path, PATHINFO_BASENAME);
}
else {
$file = 'index.php';
// Provide mod_rewrite like functionality by using the path which excludes
// any other part of the request query (ie. ignores ?foo=bar).
$_GET['q'] = $path;
}
// Override the script name to simulate the behavior without mod_rewrite.php.
// Ensure that $_SERVER['SCRIPT_NAME'] always begins with a / to be consistent
// with HTTP request and the value that is normally provided.
$_SERVER['SCRIPT_NAME'] = '/' . $file;
require $file;
【问题讨论】:
标签: php regex .htaccess google-app-engine mod-rewrite