2013-12-14 40 views
0

我试图使用htaccess的重写我的网址,但它仅在第一次查询字符串工作重写URL只适用于第一个查询字符串

我要的是重写这个URL

acnologia.com/index.php?page=images&tag=nature 

into something like this acnologia.com/images/nature 

它在第一查询字符串工作acnologia.com/images 但如果“图像”

之后添加其他目录,这是我的.htaccess代码不起作用:

RewriteEngine On 
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?page=$1&tag=$2 
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?page=$1&tag=$2 
+0

哪里是你的$ 2中定义的? – chanchal118

+0

RewriteRule ^([a-zA-Z0-9 _-] +)/([a-zA-Z0-9 _-] +)$ index.php?page = $ 1&tag = $ 2 – Andrew

回答

0

非常基本的规则将是这样

RewriteRule ^(.*)/(.*)$ index.php?page=$1&tag=$2 

和更具体的会

RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?page=$1&tag=$2 

这@Andrew在评论回答。

您的最终重写规则应该如下。指定RewriteCond以便js,css,png等文件与此重写规则不匹配。

RewriteEngine On 
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC] 
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?page=$1&tag=$2 [L,NC] 

This tutorial is helpful。

+0

它的工作原理是...代码行RewriteRule ^([a-zA-Z0-9 _-] +)/([a-zA-Z0-9 _-] +)$ index.php?page = $ 1&tag = $ 2 – Madara

+0

但我有antoher问题,在第二个查询字符串索引文件不再包含 – Madara

+0

无法理解您以前的评论。你能否提供更多细节? – chanchal118

0

原始规则中只有一个组,因此没有$ 2。

试试这个:

RewriteRule ^([a-z\d_-]+)/([a-z\d_-]+)$ index.php?page=$1&tag=$2 [NC,L] 

\ d等于0-9和NC指的nocase