douxiajia6720 2015-06-05 09:50
浏览 89
已采纳

URL重写不起作用 - Apache,本地服务器

  • I have an website on my localserver (with Apace) and i want to rewrite urls.
  • I have .htaccess file.

  • I have RewriteEngine ON (on Apache)

index.php

<a href="post.php?post=<?php echo $row['postID'];?>"><h4><?php echo $row['postTitle']; ?></h4></a>

When someone press on the title of post will be redirected to post.php/post=postID

I want to rewrite this url (localhost/post.php/post=postID) to something like that:

/localhost/post/postTitle or /localhost/post/postID

Preferably the first one.

How can I do that?

.htaccess

RewriteEngine On
RewriteRule    ^posts/([0-9]+)/?$    post.php?post=$1    [NC,L]

Nothing happens, when I press on the link, the url is the same (post.php/post=postID).

  • 写回答

1条回答 默认 最新

  • duanbeng8872 2015-06-05 10:21
    关注

    It is a manual process to update your links. So, you'll want to change:

    <a href="post.php?post=<?php echo $row['postID'];?>">
        <h4><?php echo $row['postTitle']; ?></h4>
    </a>
    

    to:

    <a href="posts/<?php echo $row['postID'];?>">
        <h4><?php echo $row['postTitle']; ?></h4>
    </a>
    

    Update: As a note, people like to use the shorthand for just echo'ing content, E.g.

    <?=$row['postID']?>

    So it would become:

    <a href="posts/<?=$row['postID']?>">
        <h4><?=$row['postTitle']?></h4>
    </a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度