gpt4 book ai didi

php - 使用 htaccess 获得良好的 SEO 链接

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:31:08 24 4
gpt4 key购买 nike

我正在构建一个 Web 论坛,其链接如下所示:

http://127.0.0.1/website/comments.php?topic_id=2/create+good+seo+links

生成链接的链接看起来像这样

<a href="comments.php?topic_id=<?php echo (int)($forum_topic['topic_id']); >/<?php echo urlencode(htmlspecialchars($forum_topic['topic_head'])); > ">

问题:如何让链接看起来像

http://127.0.0.1/website/comments/topic/create-good-seo-links/2

我尝试在 .htaccess 文件中应用此代码:

   RewiteEngine on
RewriteBase /website
RewriteRule ^comments/([a-zA-Z0-9_-)/([0-9]+)\.php$ comments.php?id=$1

最佳答案

您的 RewriteRule [a-zA-Z0-9_\-]+

中缺少右括号和限制器

您还需要将 id 指针更改为 $2,因为它匹配第二个正则表达式规则。

关于php - 使用 htaccess 获得良好的 SEO 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12623733/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com