I'm not even sure if this is possible or if I'm explaining it right but I'll give it a shot.
So basically I'm creating a web application using Javascript, HTML, CSS, SQL and PHP. I'm pretty new to backend web development, though everything is going great so far. Things are working exactly how I planned and I'm pretty proud of myself.
I have multiple users and when you go to their profile (domain.com/user/1) it displays all their info. This works the same for domain.com/user/2, domain.com/user/3 and so on.
What I'm trying to do is allow users to point their domain/subdomain to a CNAME (such as verify.mydomain.com) which allows them to connect their subdomain/domain to the web application so that it displays the same as what domain.com/user/1 does.
For example, user1 can use their domain profile.mydomain.com and it displays what domain.com/user/1 does but keeping the subdomain rather than a redirect.
If anyone has any suggestions at all on how I can do this please let me know!
Sorry about my English!
I'm not sure if you are using a self-host or a shared-host, but to solve it, you need to make some configurations(no worry, they are easy):
#1. DNS
By default your DNS server has some record like:
100.100.100.100 www.mywebsite.com
so, you need to change it to somethink like:
* .mywebsite.com
Please check if this configuration can cause some problem (I don't know if you have another application is this domain)
#2. WebServer
If you are using Apache as webserver you only need to add/change "ServerAlias" directive and the VirtualHost name (if necessary) to somethink like:
<VirtualHost test.local:80>
DocumentRoot "YOUR_APP_PATH"
ServerName test.local
ServerAlias *.test.local
</VirtualHost>
Now all subdomains(test.com, www.test.com and user1.test.com) will be redirect to some app directory.
3#. Your APP
Now you need to adjust your application logic to understand the URL and make the necessary requests.
Related
We have a php project / php web-application where users can create profiles which more or less looks like a website on a sub-domain URLs like robert.blogger.com. Now this user also has a domain of his own example robert.com. Now we want every request for robert.com to redirect to robert.blogger.com without changing the URL.
The URL should show robert.com/home.html, robert.com/aboutus.html etc. but actually code should be run from robert.blogger.com/index.html, robert.com/aboutus.html etc.
Please note that the project is hosted on a dedicated server with dedicated IPs & we also have access to the Control Panel of the user's domain.
We have tried htaccess but that only redirects, we want masking / mapping to work.
Is this possible? If so, how can this be done? Would appreciate much !!!
The solution would depend on what kind of server software you're running, but in Apache you'd do this by mapping the default vhost for the IP to the application (and then letting people point their domain to that host), and in your application use HTTP_HOST in $_SERVER to look up the valid domain (which you're probably already doing to map the subdomain to user accounts). This would be the exact same thing, as long as you keep all links relative in your HTML (and don't think "i mapped it to this user, so the domain should be user.example.com").
To give a more specific answer you'd have to be more concrete in your question.
It should be possible to use ProxyPass in htaccess, if you have permissions to use it. Try something like this.
ServerName robert.com
RewriteRule ^/(.*)$ http://robert.blogger.com/$1 [L,P]
Or you can map it in your application, depends if that server is yours and you can do anything you want to setup.
I have CakePHP 2 installed on my Apache 2 web server.
I would like to make an API for my web app and instead of accessing it through "https://www.server.com/api/...", accessing it through "https://api.server.com/...".
I really don't know how to make it work. I tried to enable a new apache site but I can only redirect to a real location on the server while I want to redirect to the "api" controller which don't really have a location on the server.
I don't know if I'm realy clear, so if you need more details, ask me.
Thanks in advance!
Sébastien
You can add a new record (CNAME) in dns zone: api.server.com to www.server.com
After you do this change, when you enter on api.server.com will be loaded www.server.com.
In your controller you can detect the hostname.
I have a web app of which I would like to create a mobile version with jQuery Mobile. The existing application is built in CodeIgniter; I'll be using the same controllers, models where I can; (especially models since I'll be needing the same data anyway, might have to write new controllers).
I'm a bit confused as to how to get started. I want to put my mobile version on a subdomain (m.myhost.tld), however.. since my app is at www.myhost.tld and I don't feel like copying it all over to another folder and maintain two, I'm a bit confused.
I know I can use the User Agent library in CodeIgniter to detect mobile browsers and load views accordingly; I just don't know how to get this working with a subdomain. Do I need to customize my app/config/routes.php file here, or can I fix this with some .htaccess magic? I have next to none experience with .htaccess though. The only thing I know is how to remove my index.php from CI apps, and that's a copypasta snippet.
EDIT: I wonder if I can use a tutorial like this one to do what I want to do? It seems to be doing more or less the same thing, just with dynamic usernames instead of a simple 'm.'
EDIT 2: Some more information, I guess.
Say I detect mobile browsers using the User Agent library included with CodeIgniter. I want to direct these browsers to m.myhost.tld. However, the content that I want to display on the mobile website comes from a controller called mobile which I can also access through www.myhost.tld/mobile/; so my question is if there is a way to route a URL like.. for example www.myhost.tld/mobile/about to m.myhost.tld/about. I'm not even sure if this is possible, teehee. Still learning!
I'll be grateful for any advice you can give me. Thanks a lot!
If you want to share the same files in different hosts, you must assign the document root folder of your sites in your web server, this is an explanation for static files, but is the base to you understand.
browser -> host:z.y.xxx[ip.ip.ip.ip] -> web server -> read filesystem : document root + browser request path
so if your document root is:
/hosting/http/z.y.xxx/htdocs
and the request is /path-to-static/index.html the server try to read:
/hosting/http/z.y.xxx/htdocs/path-to-static/index.html
In conclution, you create the new host m.mysite.tld in your web server and you change the document root as the same of the you www.mysite.tld also you could use directives of host alias, like Apache ServerAlias directive. Have lot of documentation to how you could configure a web server.
You could handle the host name in php with $_SERVER['HTTP_HOST'] variable.
If you could specify more, I could help more.
have a nice day
I want to dynamically create new sub domains on my website. i mean if you have example.com then you dynamically create sub.example.com .
i looked on google and there was nothing really good. i downloaded some scripts but they were all not working. my website is based on php so please if there is anyway i can do it in php tell me, and also if it can be possible with python then that is awesome!.
You need to setup a wildcard subdomain. Basically, anything.mysite.com will resolve to mysite.com. At that point it's up to your code to kick in and serve up the proper content depending on what subdomain the user is looking at.
http://www.google.lk/search?q=wildcard+subdomain
You can't do this unless you have permission to alter the DNS server for your domain.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I am wondering if subdomains that are created upon signup become websites or do they just give the illusion that they are websites sort of like example.com/username?
I am trying to create something like user.domain.com and can't really find something helpful to do it? Is there a way I do it so that i can allow customizations for the account for clients?
I need them to be like standalone websites so that i can go and customize them upon client requests, so what is the best way to go about it?
Subdomains usually map to a specific path on the webserver. For example, Apache specifies these paths in httpd.conf, they are called VirtualHost. An example may look like this:
<VirtualHost *:80>
ServerName subdomain.domain.org
DocumentRoot "apache2/htdocs/domain/"
</VirtualHost>
This entry maps the Uri subdomain.domain.org to the path apache2/htdocs/domain/. Now, you can modify or present a page in that path, and it won't collide with other sites.
Your DNS record will need a wildcard for *.domain.com this will allow others to know that jack.domain.com leads to a valid location.
Once that is done, your .htaccess will need to know how to handle a *.domain.com requests. More information on this can be found at htaccess subdomain redirect rules.
The gist of it is that someone goes to jack.domain.com your server sees this and then says, Ok we are passing jack as part of the query string so each page can see we are working under jack. Then in your scripts you would just use that information to pull it up and display the data for jack.
There are many different ways this can be setup, so it is hard to say how to tailor to your needs. But hopefully that is enough information to get you started. Just remember, if you are testing on localhost, localhost HOST file does not allow wildcard DNS names, so for testing you have to manually add each subdomain to that host file for testing.
The answer is quite specific to where you're signing up. There's no intrinsic connection between domains, subdomains, and hosting accounts -- you could have example.com hosted somewhere, and subdomain.example.com hosted somewhere totally different if you wanted. It's all about your host, their setup, and how you/they set up DNS.
You could accomplish this somewhat easily by having two sites, one for example.com and one for *.example.com, and have the latter base the document root on the first part of the name. In Apache, this is as simple as
VirtualDocumentRoot /path/to/site/subdomains/%1
As far as a browser would be concerned, each name represents a different site, and there'd be little or no leakage between sites if cookies are set up properly. The only problem would be FTP access, if you decide to grant that -- each user would have to be set up to have their subdir as their home dir, and ideally chrooted or something so they couldn't go and look at other people's stuff. Obviously, that will require some cooperation with/from your web host. (At the very least, in order to use VirtualDocumentRoot, they'd need to have mod_vhost_alias running. There are other ways involving mod_rewrite, but any way you do it is going to have the same issue with FTP access.)
Others have answered the main points of your question, but I did want to touch on what you call the "illusion" of a website.
There are a few different ways to serve a given application in a domain, subdomain or directory, from static files, to a single file handling every request no matter what path or domain was requested. No method is more or less "real" than any other. The only method I would call an "illusion" would be a website masked behind another website using frames, which is generally a Really Bad Idea. (Try bookmarking on a site where the URL doesn't change as you click around.)