【问题标题】:How to change file extension in php [duplicate]如何在php中更改文件扩展名[重复]
【发布时间】:2017-08-29 13:05:02
【问题描述】:

这是我正在经历的问题,解释如下:

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

2) 当我点击一个主题在博客中说“购物”时,URL 显示 xxxx/shopping.php

在我的第一个问题中,我想从 URL 中删除 .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>';
}


?>

【问题讨论】:

  • 你需要通过.htacess,re-write url with php
  • 是的,我已经创建了 .htaccess 文件并且我已经完成了这样的代码
  • 我的代码是 RewriteRule 上的 RewriteEngine ^(.*)\$ $1.php
  • 你需要处理你的路由,如果你想制作一个定制的路由器,你可以使用路由器或自己编写
  • 看不懂可以多解释

标签: php .htaccess


【解决方案1】:
RewriteEngine  on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

【讨论】:

  • 我仍然得到相同的网址
猜你喜欢
  • 1970-01-01
  • 2017-11-21
  • 1970-01-01
  • 1970-01-01
  • 2013-02-25
  • 1970-01-01
  • 1970-01-01
  • 2016-02-29
  • 2011-11-25
相关资源
最近更新 更多