[英]Hyphens in URLs with Kohana PHP Framework
這是一個Apache .htaccess問題。
在Kohana PHP Framework(我在3.1中),它們似乎不支持控制器或操作的URL中的連字符,這是域之后的前2個URL參數,如:
http://example.com/controller/action
要么
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]
在我的項目的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
);
}
);
這讓我可以做以下事情:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.