Haris Haris - 7 months ago 73
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:


to this:


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?


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]