Haris Haris - 13 days ago 6
Apache Configuration Question

Change urls with mod rewrite

I make a site migration and i need to change all my urls. I know that i can use mod rewrite rule for every link separately but i think this is wrong:
I need to change this type of URL:

example.com/categories/ad/hotels,101/hotel-1,25432


to this:

example.com/turism/hotels/hotel-1


As you can see, on new links i have a new folder "turism", id numbers and folders "ad" and "categories" are removed.

I can use this rewrite rule:

# 301 --- example.com/categories/ad/hotels,101/hotel-1,25432 => example.com/turism/hotels/hotel-1
RewriteRule ^categories/ad/hotels,101/hotel-1,25432$ /turism/hotels/hotel-1? [L,R=301]


But i have 26000 links to change and this is painful. Is there a rewrite rule that can help me speed up conversion? Is it posible to use one rewrite rule for every category?

Answer

You can use this generic rule for all of your links:

RewriteEngine On

RewriteRule ^categories/ad/hotels,[^/]*/([^,]+), /turism/hotels/$1? [L,R=301,NC,NE]