使用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修改原始网址? (或者我只是误解了事情)
答案 0 :(得分:0)
通过添加以下内容修改routes.php:
Router::connect('/javascript/:filenames/*',
array('controller' => 'combine', 'action' => 'combineJs'),
array('pass' => array('filenames')));