php - mod_rewrite 我错过了什么?

标签 php mysql .htaccess mod-rewrite

我的 .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/

相关文章:

PHP 通过 cURL 发送本地文件

php - 使用 jquery ajax 模式表单上传文件并保存文件名失败

mysql - DataGrip - 如何了解 DataGrip 中的任何表格大小?

php - 在PHP中存储下拉框选择

php - Rest Api 服务器代码不工作

.htaccess - 如何将所有具有匹配关键字的网址重定向到一个网址?

apache - htaccess 不能正常工作

php - php mysql 中的类别自动完成功能不起作用

javascript - SQL 数据和 JavaScript - 最佳实践

java - 在spring boot中在辅助数据库上创建表