在htaccess中更改后,每次点击修改URL


URL modified from each click after change in htaccess

我正在修改我的php脚本SEO友好

当我第一次点击test.php页面的链接时,它在url中显示为 http://example/test/first工作很好。当点击第二次url变成 http://example/test/test/first。测试文件夹是不断添加到URL

如何解决这个问题。

##test.php
<html>
<head></head>
<body>
<a  href='test/first'>testing</a> <br>
<body> 
</html>
##.htaccess
RewriteEngine On
RewriteBase 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
RewriteRule ^test/(.+)  /test.php?$1 [L]
DirectoryIndex test.php

解决这个问题的几种可能性

1) URL前加斜杠

 <a  href='/test/first'>testing</a>

,只有当你的网站不包含在你的网页空间的子目录

2)绝对URL

 <a  href='http://www.example.com/test/first'>testing</a>

你可以将其保存在配置文件或其他文件中(baseUrl任何人?),并动态地将其附加到链接中,如

 <a  href='<?=$cfg->baseUrl?>/test/first'>testing</a>
3) HTML

在head-Tag中设置一个像这样的基础

 <base href="http://example.com/">

可能会破坏站点上的其他路径,如image-paths和CSS路径