I have a domain domain.com
and subdomain materials.domain.com
At the domain.com
scope, I created a custom post type called resources
and a portfolio grid (using Elementor) to display it’s featured image with the title.
When clicking on the grid item, the single post is shown for example: domain.com/resources/resource-title
I’d like to remove the single post from the domain and redirect on click to materials.domain.com/resource-title
. I already have this page on the materials
subdomain).
How can I achieve that?
Sometimes this would be achievable with add_rewrite_url
but it looks like in this case it’s not as you need to redirect to a different domain.
In this case you need .htaccess or nginx rules to do this, so you need to add something like this to your nginx config for domain.com only, in order to rewrite those URLs:
rewrite ^/resources/(.+) https://materials.domain.com/$1 permanent;
You’ll likely need to restart nginx after you add this to the config file.
Happy to help if this doesn’t do exactly what you want. There’s more examples of nginx rewrite rules here: https://www.thegeekstuff.com/2017/08/nginx-rewrite-examples/