I am setting up a SaaS application written in PHP. Now every user gets a subdomain.appname.com where subdomain is user's choice. So there can be subdomain1.appname.com, subdomain2.appname.com and so on.
I have setup the CNAME entry too as a user's domain so that subdomain1.customerdomain.com points to subdomain1.appname.com and when I try subdomain1.customerdomain.com it perfectly loads the subdomain1.appname.com with subdomain1.customerdomain.com in the address bar.
As soon as I hit any link in the app, the domain in the address bar changes to subdomain1.appname.com which is obvious because there is no htaccess rule yet. And that's where I need help..I suck at htaccess, so what should be the htaccess file like to handle domain masking and keeping user's domain in the address bar all the time.
No, the problem here is not .htaccess, the problem are the links.
The application must output all links using the hostname actually used in the URL. It must not use a fixed application URL, but determine it dynamically.
Related
Sorry if the question will seem little fuzzy and you will be tempted to down-vote it as soon as you read it. I am far from being an expert in system administration but I will try to explain the problem as clearly as I can.
I need to create a website where users can have profiles and attach an external domain to their profile page on this site. Let's say we have a site:
myresume.com
User will register and create a profile and his url will look like:
myresume.com/username
The feature I need to add should enable user to point his domain to his profile url.
Is it possible via php as my whole application will be written in laravel 5.2?
I will probably need to have my nameservers or just give user the IP address which he needs to point his domain to but then I will need to fetch the domain from my side somehow and point it to the url (myresume.com/username). How can it be done?
If someone could give an explanation how it is done or at least point where to search for an answer it would be amazing. Thanks.
You need to know how Apache NGINX works.
You need to know what $_SERVER['HOST'] is.
Logic to implement this.
This is how you will do it:
Host your app on a VPS / dedicated where your app is the 'default' with no other VirtualHost.
On your index.php file, define URL. If URL is set, let your Laravel's route choose which profile_id is matched with URL and then redirect the user to that URL or render the output.
Simple?
I want to know is it possible to mask our subdomain to another domain.
e.g:
this is may doamin : mydomain1.com so my subdomain is : sub.mydomain1.com
so how could i transfer mask sub.mydomain1.com with any other domain e.d facebook.com
so when someone open sub.mydomain1.com it show sub.mydomain1.com in address bar but show contects of facebook.
i don't want to do this with php because that will use all of my bandwidth because i want to stream videos so i can't also use iframe .
Normally you would do that with a HEADER-redirect. Mostly, you can set one in the admin-panel of your domain service provider.
If you do it with javascript, the url in the browser would change.
I have wordpress website on openshift cloud. URL mydomain.rhcloud.com or http://mydomain.rhcloud.com work fine in browser.But when site access through www.mydomain.rhcloud.com URL "server is not find" shown.why this happen?
There is no record created for www.mydomain.rhcloud.com, only app-domain.rhcloud.com. if you want to add your OWN domain name like www.example.com, you need to purchase it, then add an alias to your app-domain.rhcloud.com, and setup your dns for www.example.com to point to it using a CNAME record.
I guess that the original domain name here is "rhcloud.com" and that "mydomain" is just a subdomain. In this case, "www.mydomain" is a different subdomain and it cannot be redirected to "mydomain.rhcloud.com".
To make this work, you should grant "www.mydomain" subdomain and either put your site there or make it redirect automatically to "mydomain".
Use Case: I am working on an application where user can build his own html template and publish it to his domain by selecting one. He can use different components to do this.
Issue: I want to transfer the pages build by the user from my domain to his created domain. Something similar to what is done here. Now currently in the prototye, what I do is write the content to a file (a .html file using ajax request) then make an FTP connection to the users domain (possible beacuse domains are created dynamically by the application) and transfer the files to his domain.
This, I believe, cannot be the right way and I would like to build it around a REST service which would make it flexible and also secure.
Research: I went through the web and found some website handle this very well (like the one mentioned above) and believe they have built it as a service. Am I on the ?
I would like suggestions and the possibilities so I can move forward. I am using PHP on the server side and javascript on the client side.
I can see some possible features to add safety to your services :
Check the source IP from the request, and only allow your servers to make the REST calls.
add header('Access-Control-Allow-Origin: *'); with the list of the possible domains to make the calls, instead of the *.
add security tokens related to the caller machine IP address, that would work as a password for the machine.
send all the data using post instead of get.
To update the page, I would go this way :
keep the data in the database, on server 1
add a page that reads from the database the content of the page based on a domain parameter
on the domain page call server 1 with the domain parameter to get the contents
It has been a while since I've been thinking over this feature that some websites are implementing and it looks to be very successful.
Websites like tumblr.com, blogger.com, wordpress.com allow users to register new sub-domain names from within the website by using a simple HTML/PHP form. With my current knowledge of PHP I couldn't figure out myself how this is done. I've read some posts on this and still can't build a clear idea about this.
So, how do I create a script that allows users to register their own sub-domains on my website (www.username.mydomain.com) and more than that, how do I allow them to use a different website template (as wordpress.com does). Is this possible to be done on a shared server or a dedicated server is needed?
These subdomain issues are brought down to the level of nice URLs, friendly URLs etcetera, as this feature has various names.
Basically what you do is that you set up a redirection so that if someone enters foobar.example.org, the server will serve example.org/user.php?name=foobar or example.org/foobar. After this, it's only a matter of how you put together your PHP script so that user.php or the contents of /foobar is parsed properly. The "registration" part is statically done in the .htaccess file in your DocumentRoot.
Of course this will need some sort of proper error handling for a nonexistant "subdomain".
I can tell you a simple approach.
First you have to enable subdomains in your domain. You can search for 'wildcard-dns and sub domains'. Next all is programming logic.
While registering you can ask for a unique subdomain name. After login, redirect it to the registered subdomain.
It's easy to create the wildcard subdomains. Check my post for create the wildcard subdomains dynamically in Create subdomains on the fly with .htaccess (PHP) .
How to Create Dynamic Subdomain with the help of PHP and Htaccess
We can create dynamic sub domain like top websites who provides us sub domain access with the help of username, I will try to give the best solution for the programmers. I am going to explain how to use htaccess with PHP to create dynamic sub domains, using this you can easily host multiple sub domains on single server.
Process to create dynamic subdomain
Add zone record in domain name setting
Open the setting of your Domain name provider and go to your domain DNS(Domain Name Settings), click add zone record.
Create A record and Point to IP
Now you need to create a custom A record for all your subdomains.
Select A record, HOST * POINTS TO: Your IP Address
Example : 102.30.138.121
Create a record and point to ip prashantabhishek.com
Repeat the same for host #.
Create dynamic subdomain by Prashantabhishek.com
Add CNAME record
HOST www points to # (this refers towards your IP address. )
dynamic sub domain c name record
Save the setting and enjoy the code effect.
Read more at : https://www.prashantabhishek.com/blog/view-post/how-to-create-dynamic-subdomain-with-the-help-of-php-and-htaccess/