[英]How to generate SEO friendly URL using Kohana
目前,我的url
看起来像mysite.com/product/display/10
意味着为SEO友好起见, domain/controller/function/id
是我想附加的product title
,就像product name something
一样。
以我对SEO
基本了解,对于SEO
友好,我的url
应类似于mysite.com/product/display/product-name-something/id
有没有什么有效的方式做到这一点Kohana 2.x
,如果它是不可能Kohana
,请建议在效率和更好的方式PHP
使用.htaccess
文件或无.htaccess
。
您应该使用ROUTES声明友好的URL。 在文件config / routes.php中,如下所示:
$config['route'] = 'class/method';
在您的情况下:
$config['product/display/([a-zA-Z0-9-]+)/([0-9]+)'] = 'product/display/$2';
更多: http : //docs.kohanaphp.com/general/routing
要更改字符串,请使用以下命令:
function toUrl($string) {
// small fonts
$sText = strtolower($string);
// change spaces to -
$sText = str_replace(' ', '-', $sText);
// delete all other characters to -
$sText = preg_replace('|[^0-9a-z\-\/+]|', '', $sText);
// delete too much - if near
$sText = preg_replace('/[\-]+/', '-', $sText);
// trim -
$sText = trim($sText, '-');
return $sText;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.