【问题标题】:regexp + modrewrite just work正则表达式 + mod_rewrite 只是工作
【发布时间】:2013-03-29 13:34:10
【问题描述】:

我正在尝试将旧的 Google 缓存链接重定向到我们的新网站。所以它在我的正则表达式编辑器中有效,但在我的 htacess 文件中无效?

第一条规则似乎有效,但第二条规则无效。我在规则上方留下了示例。

# 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]

【问题讨论】:

    标签: regex mod-rewrite seo


    【解决方案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} 来匹配您的查询字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-06
      • 1970-01-01
      • 1970-01-01
      • 2019-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多