创建一个SEO友好的URL

时间:2017-03-22 09:43:17

标签: php .htaccess

index.php
-------------
<?php  
    $connect = mysqli_connect("localhost","root","1234","mspl_test");
    $data = mysqli_query($connect,"SELECT * FROM products");
?>
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <form method="POST">
        <div class="container">
            <table border="1">
                <th>ID</th>
                <th>Name</th>
                <?php  
                    while($row =mysqli_fetch_array($data))
                    {

                        echo "<tr><td><a href='exp.php?id=$row[0]&name=$row[1]'>$row[0]</a>
                        <td><a href='exp.php?id=$row[0]&name=$row[1]'>$row[1]</a>";
                    }
                ?>
            </table>
        </div>
    </form>
</body>
</html>

exp.php
-------
<?php  
    $id = $_GET['id'];
    $name = $_GET['name'];
    echo "<h1 align='center'>Hello! You've selected $name having id of $id</h1>";
?>

.htaccess
---------
<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteRule ^product?$ exp.php?id=$1&name=&1

</IfModule>

当用户点击某个链接时会显示一个ID或名称..它会显示网址http://localhost/slug/exp.php?id=1&name=Google Nexus 4.我想删除此ID = 1&amp; name = Google Nexus 4并使其友好。我知道我可以用.htaccess来清理我的网址。但它不起作用。当我点击它仍然显示查询字符串网址而不仅仅是产品。

0 个答案:

没有答案