我正在为 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>
<?php
if(isset($_GET['id'])) {
//i am getting id here
}
?>
</container>
.htaccess 文件
RewriteEngine On
RewriteRule ^blog/([a-zA-Z0-9-/]+)$ blog.php?id=$1
RewriteRule ^blog/([a-zA-Z0-9-/]+)/ blog.php?id=$1
RewriteRule ^(.+)/(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
喵喔喔