Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rewrite part of a url using apache rewrite rule?

www.example.com

The site has categories like:

reptiles, vegetables, countries

And pages within each category, with urls like:

www.example.com/reptiles/iguana.html www.example.com/reptiles/black_mamba.html

Now let's say I want to change the "reptiles" category, renaming it to "lizards".

So I would need a rewrite rule and/or 301 redirect to make sure anyone who goes to the old URL will end up at the new one.

Do I need a rule for every single page (iguana.html, black_mamba.html, etc.), or is there some way I can just specify that any url with "reptiles" should have that part changed to "lizards"?

Thanks.

like image 836
Buttle Butkus Avatar asked Oct 19 '25 01:10

Buttle Butkus


1 Answers

Try this:

RewriteRule ^reptiles\/(.*) lizards/$1 [L,R=301]
like image 170
user4035 Avatar answered Oct 21 '25 19:10

user4035



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!