Haris Haris - 1 year ago 105
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?

Answer Source

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]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download