为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 php 中 mode_write seo 友好的 url 后重定向回主页

如何在 php 中 mode_write seo 友好的 url 后重定向回主页

PHP
白衣非少年 2022-01-23 10:45:11
我正在为 CMS 创建 SEO 友好的 url,我已经成功实现了它,但我面临重定向问题。索引.php<nav><a href="index.php">Home</a><a href="gallery.php">Gallery</a></nav><a href="blog/24">Read</a>单击 index.php 中的“读取”链接后,它以http://localhost/cms/blog/24重定向到 blog.php 并使用 php GET 我可以获取 id博客.php<nav><a href="index.php">Home</a><a href="gallery.php">Gallery</a></nav><container><?phpif(isset($_GET['id'])) {//i am getting id here}?></container>.htaccess 文件RewriteEngine OnRewriteRule ^blog/([a-zA-Z0-9-/]+)$ blog.php?id=$1RewriteRule ^blog/([a-zA-Z0-9-/]+)/ blog.php?id=$1RewriteRule ^(.+)/(css|img|js|images)/(.*)$ $2/$3 [L]单击阅读链接后,我将重定向到http://localhost/cms/blog/24并且我可以获得 24 的博客 ID但是如果单击 blog.php 导航部分中的主页链接,它会重定向到http://localhost/cms/blog/index.php并且它给出对象未找到错误但我希望它是http://localhost/cms/index.php
查看完整描述

1 回答

?
喵喔喔

TA贡献1735条经验 获得超5个赞

请添加斜杠以表示相对于文档根目录的路径


如果您的文件位于域的根目录中,则更改


<a href="index.php">Home</a>

<a href="gallery.php">Gallery</a>


<a href="/index.php">Home</a>

<a href="/gallery.php">Gallery</a>

否则,如果在域的子文件夹中


<a href="/subfolder/index.php">Home</a>

<a href="/subfolder/gallery.php">Gallery</a>


查看完整回答
反对 回复 2022-01-23
  • 1 回答
  • 0 关注
  • 140 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号