1
Options +FollowSymLinks

RewriteEngine On
RewriteRule ^products/([a-zA-Z]+)/([0-9]+)/$ index.php?product=$1&price=$2

这段代码使

http://www.example.com/products/computer/1000

进入

http://www.example.com/index.php?product=computer&price=1000.

是否可以制作

http://www.example.com/scriptName/arg1/val1/arg2/val2/arg3/val3

进入

http://www.example.com/scriptName.php?arg1=val1&arg2=val2&arg3=val3?

用户应该能够提供无限数量的参数。这种方式可以有/index.php?page=forum&subforum=subforum&quote1=postNo1&quote2=postNo43等等重写/index/page/forum/subforum/subforum/quote1/postNo1/quote2/postNo43

.htaccess代码看起来如何?

4

1 回答 1

1

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^([^/]+)/([^/]+)/([^/]+)(.*?)/?$ $1/$4?$2=$3 [L,QSA]
RewriteRule ^([^/]+)/$ $1.php [L]

/scriptName/arg1/val1/arg2/val2/arg3/val3这将转发一个 URI/scriptName.php?arg3=val3&arg2=val2&arg1=val1

于 2012-06-01T19:13:07.537 回答