2012-07-12 135 views
0

你能告訴我爲什麼這個重寫不會傳遞第二個值嗎? TT值被傳遞給%1,但名不在%2URL重寫不起作用

RewriteBase/
RewriteRule ^wedding-hair-and-make-up-images-([^/]*)-(.*)\.php$ franchisee-gallery.php?franchise_name=$1&id_tt=$2 [L] 
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /franchisee-gallery.php 
RewriteCond %{QUERY_STRING} name=([^\&]*) 
RewriteCond %{QUERY_STRING} tt=(.*) 
RewriteRule ^franchisee-gallery.php$ wedding-hair-and-make-up-images-%1-%2.php? [R,L] 

回答

1

的%N refeers到最後一個條件的匹配組,所以%1的條件的匹配:{QUERY_STRING} 的RewriteCond% TT =

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#RewriteCond

RewriteCond反向引用(。*):這些是的形式%N(1 < = N < = 9)反向引用,其提供對分組的部件(再次,在括號內)從當前集合中最後一個匹配的RewriteCond開始的條件。

對於你的情況,你可以重寫「特許加盟,gallery.php」的另一個PHP,這使得重定向訪問(通過HTTP頭位置)。我無法弄清楚如何通過Rewrite進行設置。也許使用PERL外部重寫程序,使用RewriteMap。


解決方案成立!使用自定義環境變量,可以將匹配的值存儲在臨時變量中!

RewriteEngine on 
RewriteBase/
RewriteRule ^wedding-hair-and-make-up-images-([^/]*)-(.*)\.php$ franchisee-gallery.php?franchise_name=$1&id_tt=$2 [L] 

RewriteCond %{REQUEST_URI} ^/franchisee-gallery.php 
RewriteCond %{QUERY_STRING} name=([^&]*) 
RewriteRule .* - [E=name:%1] 

RewriteCond %{REQUEST_URI} ^/franchisee-gallery.php 
RewriteCond %{QUERY_STRING} tt=([^&]*) 
RewriteRule .* - [E=tt:%1] 

RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /franchisee-gallery.php 
RewriteRule ^franchisee-gallery.php$ wedding-hair-and-make-up-images-%{ENV:name}-%{ENV:tt}.php? [R,L] 
+0

它不工作。我得到了一個回覆URL:wedding-hair-and-make-up-images-Patsy-31.php?franchise_name = Patsy&id_tt = 31 – user974435 2012-07-12 14:11:38

+0

是的,我想念?在Rule的末尾,清理QueryString – anibalsolon 2012-07-12 14:16:52

+0

仍然不起作用 – user974435 2012-07-12 14:19:05