我无法更改我的PHP网站中的URL结构

时间:2015-11-05 08:56:43

标签: php .htaccess url

我创建了网站,我想更改其网址结构。 例如。

http://www.haitibravo.com/market/detail.php?add_id=73

我想在没有的情况下展示它?标记为

http://www.haitibravo.com/market/product/73

我如何显示这样的网址。请帮我。我尝试了很多技巧,但我失败了。

2 个答案:

答案 0 :(得分:1)

创建.htaccess文件并将以下代码保存在其中。

RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?r=$1
RewriteRule ^([a-zA-Z0-9_-]+)/item/$ index.php?r=$1

答案 1 :(得分:0)

RewriteEngine On 
/* this enables you to write urls in desired fashion */
RewriteRule ^([a-zA-Z0-9_-]+)$ detail.php?add_id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/product/$ detail.php?add_id=$1

/*Something like this should redirecto from detail.php?add_id=n to your desired url */
RewriteCond %{THE_REQUEST} /(?:detail\.php)?\?add_id=([^&\s]+) [NC]
RewriteRule ^ item/%1? [R=302,L,NE]

/* You may need to play with the above slightly... */