[英]How to convert an SEO friendly URL to a PHP page
我想顯示我的頁面網址:
www.mypage.com/?q=picture
代替:
www.mypage.com/picture.html
我不知道如何重定向我要查看的頁面。 但是該網址不應顯示頁面擴展名,我已經嘗試過類似的操作,但是它不起作用:
<a href="?q=home" style="text-decoration: none; color: #1E90FF; font-size:25px;">Home</a>
<?php
if(isset($_GET['q']) && $_GET['q']!="" )
{
$ext=".php";
$page=$_GET['q'].$ext;
if(file_exists($page))
{
header('location:$page');
}
else
{
header('location:errorpage.php');
}
}
?>
使用.htaccess。 創建一個名為.htaccess的文件,並添加以下代碼。 希望這行得通
#rewrite file
RewriteEngine on
RewriteRule ^?q=([0-9a-zA-Z]+) $1.html
唯一的問題是,我可以去www.mypage.com/?q=mario,它將查找mario.html。
如果那不起作用,那么使用它。
#rewrite file
RewriteEngine on
RewriteRule ^home home.html
RewriteRule ^picture picture.html
這將使www.mysite.com/picture顯示所有內容,就像查看picture.html一樣
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.