使用.htaccess将网址格式化为友好网址

时间:2017-07-15 14:20:02

标签: .htaccess

我尝试使用htaccess

将我的网址格式化为友好网址

这是我的网址

  

http://localhost/index.php?go=product&id=32

我使用了REQUEST METHOD

$id = $_REQUEST['id'];
//Do some thing with php code to get info product from Mysql
$Title = $row['title'];
//Example: Computer 4GB 2CPU

但是当我想搜索我的网站时,它并不好,我希望我的网址是这样的:

  

http://localhost/product/32/Computer-4GB-2CPU

1 个答案:

答案 0 :(得分:0)

所以在你的.htaccess中,添加:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ index.php?go=$1&id=$2&product=$3 [NC,L]

<head>添加以下内容:

<base href="/">

使图像和CSS有效。

为产品添加get方法以获取名称,如果没有继续并发表评论,它应该有效。