这是一个Apache .htaccess问题。
在Kohana PHP Framework(我在3.1中),它们似乎不支持控制器或操作的URL中的连字符,这是域之后的前2个URL参数,如:
http://example.com/controller/action
OR
http://example.com/blogs/edit-article
有没有办法可以制作我的.htaccess文件,以便我可以从控制器和操作插槽中删除连字符(短划线),而不是其他插槽?这是我当前的.htaccess文件:
Options All +FollowSymLinks -Indexes -Multiviews
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
RewriteRule ^assets/(.*)$ application/views/assets/$1
RewriteCond %{REQUEST_FILENAME} !/application/views/assets/.*
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
答案 0 :(得分:2)
在我的项目的Kohana 3.1的boostrap.php中,我不得不将其添加到默认路径之上:
Route::set(
'custom',
function($uri) {
$uri = rtrim($uri, '/');
$asParts = @ explode('/',$uri);
$controller = @ $asParts[0];
$action = @ $asParts[1];
$param1 = @ $asParts[2];
$param2 = @ $asParts[3];
$param3 = @ $asParts[4];
$controller = str_replace('-','_',$controller);
$action = str_replace('-','_',$action);
$controller = (empty($controller)) ? 'home' : $controller;
$action = (empty($action)) ? 'index' : $action;
return array(
'controller' => $controller,
'action' => $action,
'param1' => $param1,
'param2' => $param2,
'param3' => $param3
);
}
);
这让我可以做以下事情: