2013-04-07 43 views
1

我试图将旧的谷歌缓存链接重定向到我们的新网站。所以它在我的正则表达式编辑器中工作,但不在我的htacess文件中?regexp + modrewrite只是工作

第一条规则似乎有效,但第二条规则不起作用。我已经在规则上面留下了一些例子。

# Legacy site redirects 
# For homes home and search: 
# www.site.ie/results_lost_found.html?search_type=lost_found&ad_type=&location_id=&x=31&y=12 
RewriteRule ^results_lost_found|results_home(.+)search_type=lost_found(.*)$ lost_found [NC,R=301,L] 
# www.site.ie/results_home.html?search_type=for_home&pet_type_id=&location_id=&x=14&y=10 
RewriteRule ^results_lost_found|results_home(.*)search_type=for_home(.*)$ for_homes [NC,R=301,L] 

回答

1

您的规则都不起作用,因为RewriteRule只匹配没有查询字符串的URI。在mod_rewrite的,你会做这样的事情:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

RewriteCond %{QUERY_STRING} ^search_type=lost_found&ad_type=&location_id=&x=31&y=12$ [NC] 
RewriteRule ^(results_lost_found|results_home)\.html$ /lost_found? [NC,R=301,L] 

注意使用查询字符串变量%{QUERY_STRING},以配合您的查询字符串。

+0

是的。这对我有效。谢谢 – 2013-04-08 11:04:55