简体   繁体   中英

URL Redirection if only certain URL is matched htaccess

I have a very small and odd issue. I want to write a rule which allows me to redirect URL.

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

to

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

but to keep in mind there are other URLs which will be made from the above like

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

I wrote a rule in .htaccess but it is causing trouble to later URLs

Redirect 302 "/category/florists/" /category/florists.html

this rule works fine but for this URL https://www.example.com/category/florists/fl/miami.html

it makes it like this

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

how can I solve it?

The mod_alias Redirect directive uses simple prefix-matching and everything after the match is copied into the end of the target URL (which explains your undesirable and malformed additional redirects).

To match just that one URL you need to use a RedirectMatch directive instead which matches against a regular expression (not prefix-matching).

For example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM