如何在.htaccess中传递多个参数

时间:2016-01-24 21:32:02

标签: php apache .htaccess mod-rewrite redirect

我有想要重写的网址,所以它可以像这样传递参数

来自 www.example.com/questions.php/postid=101&title=htaccess_tuts

www.example.com/questions.php/postid/1/title/htaccess_tuts

我一直试图使用下面的.htaccess完成这项工作,但我最终得到了这个

来自 www.example.com/questions.php/postid=1&title=htaccess_tuts

www.example.com/questions.php/postid/101

标题部分没有显示。 任何人都可以帮我传递多个参数

RewriteBase /
#Options +FollowSymLinks -MultiViews
RewriteEngine On


RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]


#here is the problem i have don this but didn't work
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+questions\.php\?postid=([^\s&]+)&([^\s&]+) [NC]
#What can i do again?
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+questions\.php\?postid=([^\s&]+) [NC]
RewriteRule ^ questions/%1? [R=301,L]
RewriteRule ^questions/([^/]+)/?$ questions.php?postid=$1&title=$2 [L,QSA]

1 个答案:

答案 0 :(得分:0)

RewriteEngine On
RewriteRule ^questions\.php/postid/([^/]*)/title/([^/]*)$ /questions.php?postid=$1&title=$2 [L]

您可以使用this网站生成重写规则