0

Does anyone know how to redirect a url that contains a parent category of a product? Basically I want to redirect a ton of products to a simple landing page that I created, so instead of making redirects for each product, I want to target the parent category (manufacturer) and redirect it to my one landing page.

So like these:

https://example.com/product/baader/baader-600/baader-600-belts/belt-rubber/ https://example.com/product/baader/baader-600/baader-600-belts/belt-urethane/ https://example.com/product/baader/baader-600/baader-600-parts/cover/ https://example.com/product/baader/baader-600/baader-600-parts/washer/ 

Would all redirect to this one landing page:

https://example.com/replacement-parts/baader/baader-600/ 

So I guess you would target anything that has "product/baader/baader-600/" and then ditch the last part of the url (/baader-600-belts/belt-rubber/) and redirect it to "/replacement-parts/baader/baader-600/" I have no idea how to make sus a RewriteRule.

2 Answers 2

0

Welcome to ServerFault.

We don't need a complex rewrites to achieve it. The following would work...

location /product/baader/baader-600/ { return 302 /replacement-parts/baader/baader-600/; } 

Rewrite equivalent...

rewrite ^/product/baader/baader-600/ http://example.com/replacement-parts/baader/baader-600/; 

If you require 301 redirect, then here are the equivalents...

location /product/baader/baader-600/ { return 301 /replacement-parts/baader/baader-600/; } rewrite ^/product/baader/baader-600/ /replacement-parts/baader/baader-600/ permanent; 
0

Assuming the manufacturer must be dynamic, then you could add such a rule.

location ~ /product/(.+) { rewrite ^.*(\/product\/)([\w|-]*)\/(.*)\/.*$ /replacement-parts/$2/$3 permanent; } Here $2 is a second match group for manufacturer, and $3 contains product part. 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.