Php mod_rewrite:帮助重写URL

Php mod_rewrite:帮助重写URL,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,我有一个网站,我正试图重写它的网址 这很简单,但我不知道怎么做 下一页是: http://localhost/site/index.php?p=home等。home是一个参数,重写应该是这样的:http://localhost/site/home.html http://localhost/site/section.php?id=someid我希望它像http://localhost/site/the-name-of-the-section-from-database-SOMEID http:/

我有一个网站,我正试图重写它的网址

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

下一页是:

http://localhost/site/index.php?p=home等。home是一个参数,重写应该是这样的:http://localhost/site/home.html

http://localhost/site/section.php?id=someid我希望它像http://localhost/site/the-name-of-the-section-from-database-SOMEID

http://localhost/site/product.php?id=someid我希望它像http://localhost/site/category-name/product-name-SOMEID

我认为这很简单,但我还是不知道怎么做。请帮帮我


谢谢

将这些行放在根目录中。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]
这一页应该对你有帮助。它为您生成htaccess文件。


使用中的这个链接有一个关于mod_rewrite的详细计划。另外,我认为anubhava的正则表达式是正确的

我可能错了,但是你不能在本地使用modrewrite。无论如何我不能,如果我被证明是错的,我想知道怎么做!可以在本地使用它,我有一个启用了mod_重写的站点,它工作了。好的,那么问题出在哪里?你没有提供任何规则吗?