【问题标题】:.htaccess redirect any chars before string.htaccess 重定向字符串之前的任何字符
【发布时间】:2013-10-23 10:19:48
【问题描述】:

我有一个这样的网址:

/anycharsinsidehere/hello-this-is-a-page-to-redirect.html

我想将它重定向到这样的静态页面:

Redirect 301 /*/hello-this-is-a-page-to-redirect.html http://www.site.com/new-page-redirected.html

我怎样才能获得这个?

我需要匹配,例如:

/dh48hsi3t8y/hello-this-is-a-page-to-redirect.html
/fnf;d3thgB/hello-this-is-a-page-to-redirect.html
/fkhg84HFB/hello-this-is-a-page-to-redirect.html
/nefjb398tFfeihg/hello-this-is-a-page-to-redirect.html

等等

【问题讨论】:

    标签: regex .htaccess redirect match


    【解决方案1】:

    要使用正则表达式支持,您需要使用RedirectMatch 而不是Redirect

    RedirectMatch 301 ^/[^/]+/hello-this-is-a-page-to-redirect\.html$ http://www.site.com/new-page-redirected.html
    

    【讨论】:

      【解决方案2】:

      使用 mod_alias,您需要 RedirectMatch 而不仅仅是 Redirect

      RedirectMatch 301 ^/(.*)/hello-this-is-a-page-to-redirect.html http://www.site.com/new-page-redirected.html
      

      使用 mod_rewrite:

      RewriteEngine On
      RewriteRule ^(.*)/hello-this-is-a-page-to-redirect.html http://www.site.com/new-page-redirected.html [L,R=301]
      

      【讨论】:

        猜你喜欢
        • 2013-07-14
        • 2017-02-09
        • 2015-03-31
        • 1970-01-01
        • 2014-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多