URL 如果只有某些 URL 匹配 htaccess 则重定向

URL Redirection if only certain URL is matched htaccess

我有一个非常小而奇怪的问题。我想写一个允许我重定向的规则 URL.

https://www.example.com/category/florists/

https://www.example.com/category/florists.html

但要记住还有其他 URL 将由上面的

制成
https://www.example.com/category/florists/fl/miami.html

我在 .htaccess 中写了一条规则,但给以后 URLs

带来了麻烦
Redirect 302 "/category/florists/" /category/florists.html

此规则工作正常,但对于此 URL https://www.example.com/category/florists/fl/miami.html

是这样的

https://www.example.com/category/florists.html/fl/miami.html

我该如何解决?

mod_alias Redirect 指令使用简单的前缀匹配,匹配后的所有内容都被复制到目标 URL 的末尾(这解释了您不需要的和格式错误的附加重定向) .

要仅匹配那个 URL,您需要使用 RedirectMatch 指令来匹配正则表达式(不是前缀匹配)。

例如:

RedirectMatch 302 ^/category/florists/$ /category/florists.html