[英]Hyphens in URLs with Kohana PHP Framework
This is an Apache .htaccess question. 这是一个Apache .htaccess问题。
In Kohana PHP Framework (I'm on 3.1), it doesn't appear that they support hyphens in URLs for the controller or action, which are the first 2 URL parameters after the domain, as in: 在Kohana PHP Framework(我在3.1中),它们似乎不支持控制器或操作的URL中的连字符,这是域之后的前2个URL参数,如:
http://example.com/controller/action http://example.com/controller/action
OR 要么
http://example.com/blogs/edit-article http://example.com/blogs/edit-article
Is there a way I can make my .htaccess file so that I can strip hyphens (dashes) out of the controller and action slots, but not the other slots? 有没有办法可以制作我的.htaccess文件,以便我可以从控制器和动作插槽中删除连字符(短划线),而不是其他插槽? Here's my current .htaccess file: 这是我当前的.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]
In Kohana 3.1's boostrap.php for my project, I had to add this above the default route: 在我的项目的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
);
}
);
This lets me do the following things: 这让我可以做以下事情:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.