如何在php中更改文件扩展名

时间:2017-04-04 11:03:28

标签: php .htaccess

这是我将要解释的问题: -

1)当我点击TAB说“blog”时,网址会显示 xxxxxx / blog.php

2)当我点击博客中的主题说“购物”时,网址会显示 xxxx / shopping.php

在我的第一个问题中,我想从网址中删除 .php扩展程序,并希望它显示为 xxxxxx / blog 而不是 xxxxxx /blog.php

在我的第二个问题中,我不仅想要从URL中删除 .php扩展名,而且还希望URL显示这样的路径; xxxxx / blog / shopping ,而不仅仅显示 xxxx / shopping.php

<?php

include("company_profile/lib/data.config.php");

// if id exists in URL
if (isset($_GET['id']))
{
$page = (int)$_GET['id'];
}
else
{
$page = '';
}

// limit of pages shown
$limit = 5;

// if page is not empty
if($page == '')
{
$page = 1;
$start = 0;
}
else
{
$start=$limit*($page-1);
}

$query = mysqli_query($conn, "SELECT * FROM blog order by id desc LIMIT            $start, $limit");

$tot = mysqli_query($conn, "SELECT * FROM blog");
$total = mysqli_num_rows($tot);
$num_page = ceil($total/$limit);

// function of pagination that showing number of pages
function pagination($page, $num_page)
{
echo'<ul style="list-style-type:none;">';

for($i=1;$i<=$num_page;$i++)
{
if($i==$page)
{
echo'<li class="pagination-button">'.$i.'</li>';
}
else
{
// <a href="http://example.com/blog/?id='.$i.'">  this is IMPORTANT your url to blog posts
echo'<li class="pagination-button"><a href="http://localhost/soft/arif.php?    id='.$i.'">'.$i.'</a></li>';
}
}

echo'</ul>';
}


?>

1 个答案:

答案 0 :(得分:0)

RewriteEngine  on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]