PHP中的友好URL

时间:2012-07-19 12:55:11

标签: php

这是我目前使用的网址路径:

/index.php?pid=211

I want to get the URL path as

/index/211/title of the product 

如何在PHP中使用用户友好的URL?

如何获得“头衔”的价值?

此致

1 个答案:

答案 0 :(得分:3)

在你的HTML代码中你必须这样写:

<a href='http://www.domain.com/index/211/title-goes-here'>url_text</a>

并在htaccess文件中修改以下内容:

Options +SymLinksIfOwnerMatch

RewriteEngine on

RewriteRule ^([a-zA-Z-]+)$ index.php?action=$1 [NC,L]

RewriteRule ^(member)-([0-9-]+)$ index.php?action=member&id=$2 [NC,L]

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

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

RewriteRule ^([0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/(.*).html$ index.php?action=details&id=$1&p1=$2&p2=$3&p3=$4 [NC,L]