使用mod重写更改网址(Change urls with mod rewrite)

我进行了网站迁移,我需要更改所有网址。 我知道我可以单独为每个链接使用mod重写规则,但我认为这是错误的:我需要更改这种类型的URL:

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

对此:

example.com/turism/hotels/hotel-1

正如您所看到的,在新链接上我有一个新文件夹“turism”,ID号和文件夹“ad”和“categories”被删除。

我可以使用这个重写规则:

# 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]

但我有26000个链接要改变,这很痛苦。 是否有重写规则可以帮助我加快转换速度? 是否可以为每个类别使用一个重写规则?

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?

最满意答案

您可以对所有链接使用此通用规则:

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

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]使用mod重写更改网址(Change urls with mod rewrite)

我进行了网站迁移,我需要更改所有网址。 我知道我可以单独为每个链接使用mod重写规则,但我认为这是错误的:我需要更改这种类型的URL:

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

对此:

example.com/turism/hotels/hotel-1

正如您所看到的,在新链接上我有一个新文件夹“turism”,ID号和文件夹“ad”和“categories”被删除。

我可以使用这个重写规则:

# 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]

但我有26000个链接要改变,这很痛苦。 是否有重写规则可以帮助我加快转换速度? 是否可以为每个类别使用一个重写规则?

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?

最满意答案

您可以对所有链接使用此通用规则:

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

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]