epicrato
epicrato

Reputation: 8418

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!

Upvotes: 1

Views: 29

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

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.

Upvotes: 2

Related Questions