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



我有一个这样的网址:

/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

等。

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

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

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

最新更新