2012-01-10 60 views
1

我有一个网站,我试图重写它的网址。mod_rewrite:帮助重写一个URL

这很简单,但我不知道该怎么做。

的页面是下的:

HTTP://localhost/site/index.php P =家庭等家庭是一个参数,重写应该是这样的:HTTP: //localhost/site/home.html

HTTP://localhost/site/section.php ID = someid,我希望它像的http://本地主机/网站/的名称-of-the-section-from-database-SOMEID

HTTP://localhost/site/product.php ID = someid,我希望它像的http://本地主机/网站/分类名/产品名称SOMEID

我想这很简单,但我仍然不明白如何去做。请帮帮我。

谢谢!

+0

我可能是错的细节ehplanation,但你不能modrewrite在本地使用。好吧,我不能反正,如果我证明错了,我很想知道如何! – 2012-01-10 12:12:35

+0

它可以在本地使用它,我有一个mod_rewrite启用的网站,它的工作。 – 2012-01-10 12:15:00

+1

好的,那么问题是什么呢?你没有提供任何规则? – 2012-01-10 12:19:55

回答

2

把这几行根的.htaccess:

Options +FollowSymLinks -MultiViews 
RewriteEngine on 

RewriteRule ^site/(home)\.html/?$ site/index.php?p=$1 [L,QSA,NC] 

# Assuming hyphen is not in the section name 
RewriteRule ^site/.*-(.*)/?$ site/section.php?id=$1 [L,QSA,NC] 

# Assuming hyphen is not in the product name 
RewriteRule ^site/[^/]*/.*-(.*)/?$ site/product.php?id=$1 [L,QSA,NC]