A Herrera
A Herrera

Reputation: 612

Redirect hundreds of URLs with specific pattern

I'm not sure how to properly write the directives in .htaccess to get URLs like this:

www.domain.com/photo/weather/p1741-high-stress.html
www.domain.com/photo/cultural-practices/p1752-thermal-convection.html
www.domain.com/photo/turf-diseases/p1748-algae-and-viruses.html

to:

www.domain.com/gallery/detail/high-stress
www.domain.com/gallery/detail/thermal-convection
www.domain.com/gallery/detail/algae-and-viruses

So essentially:

Upvotes: 0

Views: 44

Answers (2)

Josh Withee
Josh Withee

Reputation: 11336

Regex to match original URLs:

www\.domain\.com/photo/[^/]+/p\d+-(.+?)\.html

Replace it with:

www.domain.com/gallery/detail/$1

Upvotes: 0

Croises
Croises

Reputation: 18671

You can use:

RewriteEngine on
RewriteRule ^photo/[^/]+/p\d+-(.+)\.html$ gallery/detail/$1 [NC,R=301,L]

Upvotes: 1

Related Questions