[英]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
写了一条规则,但它给以后的 URL 带来了麻烦
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.