我有以下网址。我试图传递搜索字词。我不关心其他参数。我打算为每个搜索类型创建一个规则,因为它们在newdomain上有不同的键/值。
http://example.net/Search/Action?type=town&search=springfield&val2=1&val2=1&submit=Search
http://example.net/Search/Action?type=city&search=springfield&val2=1&val2=1&submit=Search
我想将它重写为这些
http://newdomain.com/search/a?searchtype=t&searcharg=springfield&SORT=D&submit=Search
http://newdomain.com/search/a?searchtype=c&searcharg=springfield&SORT=D&submit=Search
我无法让这些工作。
RewriteRule ^/?type=city&search=(.*)&val1=1&val2=1&submit=Search$ http://newdomain.com/search/a?searchtype=c&searcharg=$1&SORT=D&submit=Search
RewriteRule ^/?type=town&search=(.*)&val1=1&val2=1&submit=Search$ http://newdomain.com/search/a?searchtype=c&searcharg=$1&SORT=D&submit=Search
答案 0 :(得分:1)
这应该有效:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /Search/Action\?type=town&search=(.*)&val2=(.*)&val2=(.*)&submit=(.*)\ HTTP
RewriteRule ^ http://newdomain.com/search/a?searchtype=t&searchg=%2&SORT=D&submit=search\? [R=301,L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /Search/Action\?type=city&search=(.*)&val2=(.*)&val2=(.*)&submit=(.*)\ HTTP
RewriteRule ^ http://newdomain.com/search/a?searchtype=c&searchg=%2&SORT=D&submit=search\? [R=301,L]