2012-07-12 222 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