Creating multiple landing pages with subdomains
I have to create landing pages on multiple subdomains e.g. shop.thedomain.com and academy.thedomain.com
The pages are already built on thedomain.com Wordpress install. Is there a way to assign these subdomain URLs to these pages without creating brand new Wordpress installs in the subdomain directory and without using redirect; eg instead of redirecting the subdomain shop.thedomain.com to thedomain.com/shop the url bar should show the address as shop.thedomain.com and load the page content that exists at thedomain.com/shop
Same with academy.thedomain.com . There has to be a way to do this without duplicating the Wordpress install files and database for one landing page labeled and accessible from the subdomain address
19 Replies
you can configure nginx to proxy the requests from the subdomain to those specific urls
but the links and everything else would point to the other domain
Where do I find the nginx configuration? And are there any settings in particular I should be I’m looking for ?
that depends on the server :/
Is there similar configuration available on Apache ?
I’m so dense with backend. So reverse proxy either Apache is what I’m looking for ?
the idea is to actually have apache do the request for you
so, when someone requests
abc.example.com
, apache creates an http request to example.com/abc
you can also implement this in php with file_get_contents
you create an index.php file for the sub-domain and have it just send the contents
(you will be better off using curl or fopen instead)I want the contents of example.com/abc to be shown for the request to abc.example.com , the point is I don’t want to have to make a whole separate Wordpress install and duplicate database under the sub domain files when everything already exists on the main domain files. And redirect would change the address in the url bar.
Forgive me if I’m misunderstanding
i know what you what, and this is how you do it
Okay thank you
I was confused what you meant by the index.php for the subdomain but I guess it could be an empty file ? It just needs to exist ?
you'd basically create a sort of proxy on your own in PHP, but it's a terrible solution compared to just using Apache
mod_proxy
that index.php would live in the subdomain and using mod_rewrite
receive all the requests for that subdomain, then act as a router to fetch and display data from the other site by it doing an HTTP request
it's one of those "yeah, it would technically work" solutions
I'm using mod_proxy on my home server to pass some traffic on a subdomain through to a raspberry pi. This is in the apache config file for the subdomain I'm using:
at the end of the day, this is much more a sysadmin issue than a programmer issue though. Not to say it's not something to ask here, just that if you've got a sysadmin where you work, dump this on their deski couldnt have said it any better
the index.php solution is the last last last last last resort
so last that papa roach wouldnt sing about it
you only use this because you have to
Gotcha, and good to know thank you. On this particular site I wear all the hats so unfortunately no one to delegate to 😆
sorry that you have to wear the most horrible hat of them all: scuffed jeans with furr devops
Ah, the hat of all hats. I've worn it often
i hate wearing that hat
Is it true this should work for subdomains that just need to serve the content of another page:
make a CName in dns record where the Name is the subdomain (eg for ‘portfolio.mydomain.com’ the Name would be ‘portfolio’) and the Value of the Cname would be the IP or the url of the page whose content you want to serve (e.g. https://mydomain.com/portfolio-items)?
CNAMEs only allow you to have an alias for another DNS record, so
CNAME portfolio.mydomain.com mydomain.com
will cause your client to do a second DNS record call to find the IP for mydomain.com, but it cannot be used to redirect the client, and especially not to a URL with a protocol as DNS is entirely protocol agnostic.
You can have a virtual host on your server which accepts traffic for portfolio.mydomain.com, which can be CNAMEd to the A record of mydomain.com, that will then server a different folder on the server thoughI just cannot wrap my brain around all of this
But I thank you all for trying to explain ❣️