如何使permlink大写为小写

时间:2016-03-26 06:06:32

标签: php url-rewriting seo permalinks

我使用SEO URL成功更改了permlink,但我面临大写问题。我用<a href="<?php echo str_replace(' ', '-', $row['title']);?> 改变了 detail.php 并创建了.htaccess`

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.birthdaycakenames.com [NC]
RewriteRule ^(.*)$ http://birthdaycakenames.com/$1 [L,R=301]

AddDefaultCharset UTF-8
RewriteRule ^/(css|js|img)/(.*)?$ /$1/$2 [L,QSA,R=301]
RewriteRule ^([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)/?$ detail.php?title=$1&id=$2

RewriteRule ^([a-zA-Z0-9-/]+)/?$ detail.php?id=$1
Options -Indexes

现在我想将大写url更改为小写。

1 个答案:

答案 0 :(得分:1)

您可以在PHP中尝试此功能

$Title = 'For Example Title';
function seoUrl($string) {
    $string = strtolower($string);
    $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
    $string = preg_replace("/[\s-]+/", " ", $string);
    $string = preg_replace("/[\s_]/", "-", $string);
return $string;
}
echo seoUrl($Title);

替换此代码 <?php echo seoUrl($row['title']);?>