繁体   English   中英

如何将SEO友好的URL转换为PHP页面

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM