简体   繁体   中英

In .htaccess, how do I redirect a url when a word is alone?

I have a situation where I need to create multiple redirects.

I want to redirect /blog to /food, which can be easily done by

Redirect 301 /blog /food

But then I also need to redirect /blog/example to /another-example. But because I created the former redirect, this is what ends up happening:

/blog/example

becomes

/food/example

instead of

/another-example

because it's changing /blog to /food before considering anything else.

Any help? Thanks!

Redirect directive matches rest of the uri and appends it to the destination. To redirect a specific uri, you need to use RedirectMatch.

RedirectMatch 301 ^/blog/?$ /food

Clear your browse cache before testing this.

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