我的 .htaccess 文件中有以下内容:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/$ /index.php?p=$1 [L]
这会更改
的网址http://domain.com/index.php?p=101
到
http://domain.com/101/
这一切都很好。但!在我的index.php 中,我有一段代码来列出这样的链接:
//getting links
$sqlLinks = "SELECT pid, linkh1 FROM pages WHERE draft= '0' AND pid > 100 ORDER BY linkh1 ASC";
$query = mysqli_query($myConnection, $sqlLinks) or die (mysqli_error());
$Links = '';
while ($row = mysqli_fetch_array($query)) {
$pid = $row["pid"];
$linklabel = $row["linkh1"];
$Links .= '<li><a href="http://domain.com/index.php?p=' . $pid . '">' . $linklabel . '</a></li>>
当我单击或将鼠标悬停在链接上时,它仍然显示
http://domain.com/index.php?p=101 link.
我不明白的是如何使所有链接自动显示为:
http://domain.com/101/
http://domain.com/102/
http://domain.com/103/
etc...
最佳答案
.htaccess 文件路由传入请求。
要重写传出链接,为什么不直接格式化它呢?
$Links .= '<li><a href="http://domain.com/' . $pid . '">' . $linklabel . '</a></li>'
关于php - mod_rewrite 我错过了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4984724/