使用PHP中的动态URL重写URL

时间:2014-03-18 22:56:24

标签: php .htaccess url

我已经在堆栈上查看了一些URL重写问题,并且已经开始实现已发布的解决方案,但我无法让它工作。我正在使用动态网址来发布帖子。因此,每个帖子都有一个ID,原始网址如下:localhost/post.php?=id。我目前正试图获得localhost/post/id

以下是.htaccess的片段:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On

RewriteBase /


RewriteRule ^/post/([0-9]+)/?$ /post.php?=$1 [L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . routing.php

3 个答案:

答案 0 :(得分:1)

尝试:

RewriteRule ^post/([0-9]+)?$ post.php?id=$1

您必须写下您的链接:<a href="post/<?=$id;?>"><?=$title;?></a>

并提交post.php文件

echo $_GET['id'];

答案 1 :(得分:0)

RewriteRule ^/post/([0-9]+)/?$ /post.php?=$1
                                         ^ perhaps a key for this value?

答案 2 :(得分:0)

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