.htaccess在字符串之前重定向任何字符

时间:2013-10-15 14:44:13

标签: regex .htaccess redirect match

我有这样的网址:

/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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:1)

使用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]