How to redirect blog.example.com to example.com/blog

I am moving the blog from a subdomain (blog.example.com) to the main domain (example.com/blog).

I need to redirect all posts (301) from the old url to the new:

blog.example.com/2020/03/example-post
blog.example.com/2023/06/another-post

Must become:

example.com/blog/example-post
example.com/blog/another-post

Is it possible to achieve that? Can I do that on the Pro plan?

What configuration / rules should I use?

Thanks

Hi,

To redirect the examples you’ve given, you could use a Redirect Rule. Use Example 5 below, but also check the substring() function in Example 6 to remove the date element:

Thanks for the reply!

substring would match any string, however I only need to match /2020/03/ or /2023/06/ or any other date, etc. but not for example a path like blog.example.com/category/my-category

You’d need to create more than one rule. How many? Not sure, depends on your sitemap.

For instance, in the rule for the paths starting with /YYYY/MM, you can use the “When incoming requests match…” expression to exclude any request with URI Path starting with /category or /tag (if you also use those), or not starting with /2023/ (and previous years if applicable).

Then one or more other rule(s) would just redirect all remaining paths, including /category..., /tag...., but also the remaining paths on your installation (/robots.txt, /sitemap.xml, etc.)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.