htaccess 哈希 url 重定向到没有连字符的哈希问题

htaccess hash url redirection to without hash issue with hyphens

我在 angular 应用程序中遇到 url(散列)重定向问题。我尝试用 angular 方式修复它,但它不起作用,所以我使用自定义 .htaccess 方式。该解决方案工作正常,但我遇到了带有连字符的(重复)URL(s) 的问题。示例如下。

.htaccess

RewriteEngine On
RedirectMatch 301 ^/terms    http://example.com/#terms
RedirectMatch 301 ^/terms-bb http://example.com/#terms-bb

按照上面的例子,如果打开“http://example.com/terms-bb”,它会重定向到“/terms”。那么有什么办法可以严格匹配这些重复的 urls?

您只在开头锚定了您的模式,因此 ^/terms 匹配任何 /terms.

开头的内容

如果你想要严格匹配,那么也把它锚定在最后 – ^/terms$.