2014-02-27 18 views
1

我有这样的链接(未知数量的变量),我想改变:mod_rewrite正则表达式:“.../auto/bmw?year = 2014&...”to“.../auto.php?company = bmw?year = 2014&...”

http://test.my/news/auto?year=2014&thema2=design 
http://test.my/news/auto?year=2005&... 
http://test.my/news/moto?year=2012&month=10&championship=MotoGP 

进入这样的:

http://test.my/news.php?thema=moto&year=2012&month=10&&championship=MotoGP 
http://test.my/news.php?thema=auto&year=2014&thema2=design 

我试图这样做,但没有成功:

RewriteRule ^news/([a-zA-Z_.]+)\??([a-zA-Z0-9_-.]+)$ news.php?thema=$1&$2 [NC,L,QSA] 

PHP vardump($ _ GET):

array(6) { 
["thema"]=> string(5) "mot" 
["o"]=> string(0) "" 
["year"]=> string(4) "2012" 
["month"]=> string(2) "10" 
["championship"]=> string(6) "MotoGP" } 

我认为这是一个问号,并用正则表达式的第二部分的问题。 请告诉我这是如何做得更好。谢谢。

+1

你不必让你重写查询部分。只要你使用'[QSA]',参数就会自动传输。 – h2ooooooo

回答

1

将这个规则在你的根.htaccess

RewriteRule ^(news)/([\w-]+)/?$ $1.php?thema=$2 [NC,L,QSA] 
+0

对不起我的错。我编辑了这个问题。 (结果必须是“my server.com/news.php?class=auto&company = ...”) – Vladislav

+0

ok查看更新的答案。 – anubhava

+0

最后更改。 (我很着急)/ news/moto?year = 2012&< - moto和year之间的问号。 “news”= news.php他们= moto yaar = ...等 – Vladislav