繁体   English   中英

如何使用Kohana生成SEO友好URL

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM