Welcome Guest, Not a member yet? Register   Sign In
Wildcard subdomains
#1

Hello, I'm creating a project where on user register, they will have their own dynamic subdomain based on the username. 

So then, for example, when a user goes to myname.domain.com, it will in reality be domain.com/user/myname but the url will stay as myname.domain.com.

Any suggestions are appreciated.
Reply
#2

I would recommend to address it in your webserver configuration, or any other piece of infrastructure software you have in front of your web-app. This might be Web Application Firewall (WAF), or Reverse Proxy (like nginx), or probably with mod_rewrite if you are using Apache.

In this case you will implement Users controller in CI4 with routing you like (e.g. domain.com/users/myname), and then can forward requests coming to myname.domain.com to that URL.
Reply
#3

(This post was last modified: 02-25-2020, 10:54 AM by jameslittle.)

I've looked at doing something similar to this, and you should be able to do that with a wildcard DNS entry. Then it's just a matter of getting your server to respond to any subdomain.

If you need to create full DNS entries for each subdomain, you can use Namecheap's developer API to make the dynamic DNS records work (however, this probably isn't necessary if you can use wildcards).

You might read up on their system:

https://www.namecheap.com/support/api/me...set-hosts/



Obviously the DNS would need to be in their system for that to work.



If you want to use Cloudflare's DNS, you can do something similar with their API. I believe this works with both free and paid Cloudflare accounts.


https://api.cloudflare.com/#zone-edit-zone
Designer, developer and Diet Dr. Pepper addict. Messing up PHP since <?= $when['year';] ?>
Reply
#4

@zahhar @jameslittle thanks for the helps guys, however, I found something a little better.

$routes->get('/', 'Dashboard\Profile::index', ['subdomain' => '*']);

This is still working perfectly, however, I'm not getting the session to my subdomains but I'm still looking for a fix to that.

If anyone has an idea on how to do this, it would be very appreciated.
Reply
#5

(02-25-2020, 09:52 PM)Smil3y Wrote: @zahhar @jameslittle thanks for the helps guys, however, I found something a little better.

$routes->get('/', 'Dashboard\Profile::index', ['subdomain' => '*']);

This is still working perfectly, however, I'm not getting the session to my subdomains but I'm still looking for a fix to that.

If anyone has an idea on how to do this, it would be very appreciated.

May I ask you if you did any changes in DNS or webserver to actually allow subdomains? Or they just work out of the box for you?
Reply
#6

(02-26-2020, 07:44 AM)zahhar Wrote:
(02-25-2020, 09:52 PM)Smil3y Wrote: @zahhar @jameslittle thanks for the helps guys, however, I found something a little better.

$routes->get('/', 'Dashboard\Profile::index', ['subdomain' => '*']);

This is still working perfectly, however, I'm not getting the session to my subdomains but I'm still looking for a fix to that.

If anyone has an idea on how to do this, it would be very appreciated.

May I ask you if you did any changes in DNS or webserver to actually allow subdomains? Or they just work out of the box for you?
Well, my friend set this up but you just need a A record in your domain and then you just put in the virtualhosts file and that should be it.

Btw., I got the sessions to work in my subdomains by changing the $cookieDomain options in App.php to '.domain.com'.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB