Mapping a custom domain for redirections (url shortener)
Hello everyone, thanks for reading and helping
This is a recap of the situation:
- I want to create a url shortener platform (for my projects)
- Each tenant/project is accesible from the "{originaldomain}/admin/" (shared for all the projects, limited access depending user)
- Each tenant/project has a profile field to add a custom domain
- Each link I create should have this url structure: {custom_domain}/{string of characters}
Shortened url creation process example:
- Add {custom_domain} to the Tenant/Project (https:// customdomain .com)
- Add final/original url (https:// google .com)
- Add the shortened slug (abcd1ef)
- Generated url » https:// customdomain .com/abcd1ef
- If visit the Generated url = redirected to final/original url (https:// google .com)
The problem is that right now, if I do that, it works perfectly and it generates the URL. But, as the {custom_domain} is not mapped to the platform, it gaves an error
I know that, as a user in these kind of services like Bitly, you create a CNAME in your {custom_domain} DNSs to their Server IP.
But I have no idea how to manage it from the other side, from the creator side. Because if I do that CNAME, the domain gives an error as is not configured in the Platform
Thanks for your help!
Solution:Jump to solution
They have an Aliases option, the thing is that it doesn't seem the best option if the users can add their own domains and how to update that list "automatically".
Thanks for the info, I will try it now manually with this test domain and find more info about it...
12 Replies
But I have no idea how to manage it from the other side, from the creator side. Because if I do that CNAME, the domain gives an error as is not configured in the PlatformWhat's the error? I think by default all routes on a Laravel app should work for any domain unless you specify a specific domain I guess you might run into issues, as you have a wildcard on the root
/{shortcode}
Hello Dennis, thank you for your reply.
Well, I'm not saying it's an error per se. I just don't know how to handle that situation.
I will add realistic data so it's easier for examples:
- Project domain: prolinks .pro
- Project Filament Admin: prolinks .pro/app/
- Tenant Admin Url: prolinks .pro/app/ibontech
- Tenant custom domain field: ibon .tech
- Ibon .tech edit DNS A record to = Server IP where the project is located
Situation 1 » Creating a url with the slug "dudvf0"
- Example "prolinks .pro/dudvf0" (you can try it)
- It works, it redirects to "productividad .pro"
- Not the use case I'm looking for, I want users to use their own custom domain
Situation 2 » Creating a url with the slug "dudvf0"
- Example "ibon .tech/dudvf0" (you can try it)
- It doesn't work, domain gives error "ERR_EMPTY_RESPONSE"
Routes code for the fallback using the "prolinks .pro" base url before slug
I'm not an expert developer, so maybe I'm not explaining myself correctly.
Thank you!
Not sure about your server setup (nginx/apache), but you probably need to set a wildcard for the server if you haven't yet
I'm using Laravel Forge + DigitalOcean
In settings I see and it's activated the "Allow Wildcard Sub-Domains" but I don't see option for custom domains that users may add.
I'm not using Forge so I am not sure whether they have an option for "Aliases".
Solution
They have an Aliases option, the thing is that it doesn't seem the best option if the users can add their own domains and how to update that list "automatically".
Thanks for the info, I will try it now manually with this test domain and find more info about it
It works! Without SSL for now » https://ibon.tech/dudvf0
https gives an error, will search more info about it
Edit: now works with SSL also. will update this thread if I manage to automate things so other people can see it
It seems that Forge creates a file so not configured domains do not work
https://forge.laravel.com/docs/sites/the-basics.html#protecting-against-unconfigured-domains
I moved the file to parent folder and removed the alias for the extra domain and still works. Will try to add another domain to test it if just with DNS change works.
Also, if this works, I suppose have to add a functionality (on the route) to find if that domain is in the Database so I limit (me, not Forge) which domain works.
Important if you are reading this: I'm not a developer, maybe I'm doing awful things.
The Basics | Laravel Forge
Deploy your Laravel PHP application painlessly
So, it seams the option is to use the Forge API to add aliases:
https://forge.laravel.com/api-documentation#add-site-aliases
API Documentation
Laravel Forge provides a rich HTTP API that allows you to programmatically provision and manage your PHP application servers.
So, when a new Project is created, I suppose I can send a POST request to add the new custom_domain
Would have proposed the same but thought you figured out how to change the server config.
The thing is that I'm not expert with servers, but I defend myself with API. So I manage to make it work that way
In the handleRegistration function I added the Http::put and worked fine