htaccess 重定向 - 301 上更严格的匹配?

发布于 2024-09-14 15:27:06 字数 365 浏览 0 评论 0原文

以下基于 htaccess 的重定向规则工作正常:

Redirect 301 /content/category/2/24/30/ /new/c/url/

问题是它工作得太好了。如果用户访问

/content/category/2/24/30/50/50/

它将重定向到:

/new/c/url/50/50/

如何让它进行严格匹配?将两个示例重定向为简单的:

/new/c/url/

就可以了,否则忽略较长的版本也很好。

谢谢!

The following htaccess based redirection rule works fine:

Redirect 301 /content/category/2/24/30/ /new/c/url/

The problem is it works too well. If a user goes to

/content/category/2/24/30/50/50/

it will redirect to:

/new/c/url/50/50/

How can I get it to do a strict match? Either redirecting both examples to simply:

/new/c/url/

would be fine, otherwise ignoring the longer version is good too.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

咋地 2024-09-21 15:27:06

Redirect 匹配路径前缀和不仅仅是整个路径。如果给定的路径前缀与请求的路径匹配,则从前缀开始的剩余路径将附加到替换路径。

因此,请使用 RedirectMatch 代替^$ 标记路径的开始和结束:

RedirectMatch 301 ^/content/category/2/24/30/$ /new/c/url/

Redirect matches path prefixes and not just the whole path. If the given path prefix matches the requested path, the remaining path from the prefix on is appended to the replacement path.

So use RedirectMatch instead with ^ and $ marking the start and end of the path:

RedirectMatch 301 ^/content/category/2/24/30/$ /new/c/url/
邮友 2024-09-21 15:27:06

解决方案应该是

RedirectMatch 301 ^/content/category/2/24/30/$ /new/c/url/

基本上你说的 30/ 是字符串的结尾。

我无法尝试,所以如果不起作用请告诉我。

^ 匹配字符串的开头,$ 匹配字符串的结尾。

如果您想了解更多信息,请阅读以下内容:http://www.regular-expressions.info/

And the solution should be

RedirectMatch 301 ^/content/category/2/24/30/$ /new/c/url/

Basically you're saying the 30/ is the end of the string.

I can't try it so let me know if it's not working.

^ matches the beginning of a string and $ matches the end of a string.

Read this if you want to know more about it: http://www.regular-expressions.info/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文