php - 如何使permlink大写为小写

标签 php url-rewriting seo permalinks

我成功地更改了带有 SEO URL 的永久链接,但我遇到了大写问题。我用 <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 更改为小写。

最佳答案

你可以在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']);?>

关于php - 如何使permlink大写为小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36232186/

相关文章:

apache mod_rewrite 用于自动发现 url

php - 没有 http|https 的外部链接失败

indexing - 防止搜索引擎索引我的 api

grails - 在 Grails 应用程序中创建 "pretty"用户配置文件 URL

php - 验证多级关系依赖关系的最佳方法

php - 如何在 Codeigniter 中使用 IN 运算符进行绑定(bind)查询

apache - 别名和重写器一起工作

php - mb_internal_encoding() 虽然已配置但不可用?

javascript - 当我单击更新按钮时,它不会更改/更新(CodeIgniter,更新多行)

javascript - 如何避免网站中的自定义/服务器错误?