ZgrKARALAR
ZgrKARALAR

Reputation: 489

Nginx parse and redirect to other domain

I wanna make some redirect but for this i need to parse domain to send other domain.

My old domain url like this

http://olddomain.com/bg/some-name-part-421.html

http://olddomain.com/bg/some-name-1231.html

http://olddomain.com/bg/some-name-product-name-221.html

I want to redirect this to like this

https://www.newdomain.com/magazin/some-name-part.html

https://www.newdomain.com/magazin/some-name.html

https://www.newdomain.com/magazin/some-name-product-name.html

I try to redirect them like this on server block

rewrite ^(/bg/)([a-z-]+-[0-9]+)\.html$ http://www.newdomain.com/magazin/$2 permanent;

Not working well making redirect like this

http://www.olddomain.com/bg/chervena-borovinka-bioherba-3694.html

https://www.newdomain.com/magazin/chervena-borovinka-bioherba-3694

I want to delete also as last part of number and - but i dont know why not working well

Upvotes: 1

Views: 58

Answers (1)

Marcelo
Marcelo

Reputation: 1592

Thats my .htaccess:

RewriteEngine On
RewriteRule "^bg\/([^0-9]+(?<!-))-([0-9]+)(\.html)" "http://newdomain.com/magazin/$1$3" [R]

Dont forget to set the RewriteBase.

Heres the code: https://regex101.com/r/UdMqaQ/3/

Nginx

rewrite "^/bg\/([^0-9]+(?<!-))-([0-9]+)(\.html)" "newdomain.com/magazin/$1";

Upvotes: 1

Related Questions