【问题标题】:mod_rewrite what am I missing?mod_rewrite 我错过了什么?
【发布时间】:2011-02-13 14:38:23
【问题描述】:

我的 .htaccess 文件中有以下内容:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/$ /index.php?p=$1 [L]

这会改变

的 url
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...

【问题讨论】:

    标签: php mysql .htaccess mod-rewrite


    【解决方案1】:

    .htaccess 文件路由传入请求。

    要重写传出链接,为什么不正确地格式化它?

    $Links .= '<li><a href="http://domain.com/' . $pid . '">' . $linklabel . '</a></li>' 
    

    【讨论】:

      【解决方案2】:

      mod rewrite 只负责重写您的请求。

      它与您在网站中输出的 html 代码无关。

      有可用的模块可以进行后期处理并负责处理,但它们非常罕见

      通常的方法是按照您希望的方式打印链接

      【讨论】:

        猜你喜欢
        • 2011-09-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-11
        • 1970-01-01
        • 2019-08-29
        相关资源
        最近更新 更多