2016-07-23 34 views
1

我試圖從重定向到/somedir/index.php?action=something&id=x/index.php?action=something&id=xhtaccess的重定向,如果一個查詢參數相匹配

只有action = somethingid是動態的。

最近我試過這個沒有運氣。這有什麼問題?

<IfModule mod_rewrite.c> 
RewriteCond %{QUERY_STRING} (^|&)action=something($|&) 
RewriteCond %{QUERY_STRING} (^|&)id=($|&) 
RewriteRule ^somedir/index\.php$ /index.php?action?something&id=%2$ [NC,R] 
</IfModule> 

注意:somedir在它的htaccess中有一個index.php和這個規則。這會導致衝突嗎?

RewriteRule ^.*$ index.php [NC,L] 

回答

0

試試這個規則,而不是您的規則在.htaccess

<IfModule mod_rewrite.c> 
RewriteCond %{QUERY_STRING} (^|&)action=something($|&) 
RewriteCond %{QUERY_STRING} (^|&)id=x($|&) 
RewriteRule ^somedir/index\.php$ /index.php?action=something&id=x [L,R=301] 
</IfModule> 

結果將不會發生衝突。

+0

我看到'ID = x'該規則。這是否意味着'ID'將始終是'X'?這是一個動態參數 – rzr

+0

X將在第二個條件下獲得價值。 – error2007s

+0

似乎不起作用:/ – rzr

0

您可以使用:

<IfModule mod_rewrite.c> 
RewriteCond %{QUERY_STRING} (?:^|&)(action|id)=([^&]+)&(?:.*&)?(action|id)=([^&]+)(?:$|&) [NC] 
RewriteRule ^somedir/index\.php$ /index.php?%1=%2&%3=%4 [NC,L,R=301] 
</IfModule>