您好 stackoverflow 社区希望您了解我正在尝试做什么
我使用htaccess
和 php 使用漂亮的 URL ,在某些页面中,我看到URL中出现类似新闻标题的内容。 ..
http://www.samplePage.com/news/killer-shooter-in-new-york
我想知道我是怎么做到的,我在htaccess或友好的URL中不太好,但是我尽力而为,这就是我这样做的方式。...
我的 .htaccess
Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9/]+)$ index.php?view=$1
我的 html
//after the header label i add this to include the content
<?php
if (isset($_GET["view"])) {
$view=explode("/",$_GET["view"]);
include"modules/".$view[0]."-view.php";
}else{
include"modules/home-view.php";
}
?>
现在我获得了这些链接,这些链接将我带到了新闻
<ul class="row news-list">
<?php $sql=$con->query("SELECT * FROM latest_news LIMIT 4");
while ($row=$sql->fetch_array()) { ?>
//note: the URLSERVER is the route for example http://localhost/projectNews/
<li class="grid_6">
<a href="<?php echo URLSERVER?>news/<?php echo $row['id']?>/"><?php echo $row['post_title']?></a>
</li>
<?php } ?>
</ul>
此的输出为http://localhost/projectNews/news/4/
一旦我单击链接,我想做的就是在新闻ID后面添加新标题,例如我之前解释过的...
http://localhost/project/news/4/killer-shooter-in-new-york
你们中有人可以帮助我吗?我对此有点新意,谢谢!