mod_rewrite更改原始URI

时间:2011-11-18 11:18:32

标签: cakephp mod-rewrite

使用mod_rewrite(和CakePHP):

RewriteRule ^javascript/(.*)  /combine?type=javascript&files=$1 [PT,L]

我想改变

http://bla.com/javascript/flyout.ribbon.js,jquery.min.js

http://bla.com/combine?type=javascript&files=flyout.ribbon.js,jquery.min.js

问题是CakePHP查看原始URL(在下面的parseParams()内部)http://bla.com/javascript/并决定我要访问 JavascriptController / javascript而不是 CombineController /在Dispatcher.php中结合

public function dispatch(CakeRequest $request, CakeResponse $response, $additionalParams = array()) {
    if ($this->asset($request->url, $response) || $this->cached($request->here)) {
        return;
    }

    Router::setRequestInfo($request);
    $request = $this->parseParams($request, $additionalParams);
 .....
}

public function parseParams(CakeRequest $request, $additionalParams = array()) {
    if (count(Router::$routes) == 0) {
        $namedExpressions = Router::getNamedExpressions();
        extract($namedExpressions);
        $this->_loadRoutes();
    }

    $params = Router::parse($request->url);
    $request->addParams($params);
.....
}

有什么办法可以使用mod_rewrite修改原始网址? (或者我只是误解了事情)

1 个答案:

答案 0 :(得分:0)

通过添加以下内容修改routes.php:

Router::connect('/javascript/:filenames/*', 
                array('controller' => 'combine', 'action' => 'combineJs'), 
                array('pass' => array('filenames')));