Creating custom domain names for api - .htaccess

I have a web server using cpanel and I would like to use a custom domain on one folder for an api. So if I created a folder called api in the public_html folder then the path to that folder would be www.example.co.uk/api/(some php file). How could I change it so the folder would become a custom domain of api.example.co.uk/api/(some php file).
I have looked at a few options but don't really know the best way. I have tried to add a htaccsess file to the api folder and then create a rewrite rule to rewrite the www to api.
I also then looked at creating sub domains with the path to the api folder.
I have read that creating a A record on the server could work but I'm not quite sure how to do this. I know it can be done as most apis use some custom domain like facebooks graph api. (i.e https://graph.facebook.com/youtube/)

This will depend on if you have access to make DNS records for your root domain, example.co.uk. For example right now www. is a CNAME or A record (depends on how your web server is set up), that resolves to the address of your web server. If you made an identical record but named it api. (api. IN A ip-of-webserver), then api.example.co.uk would do the same thing that www.example.co.uk does. This is kind of pointless if they go to the same web server though, the /api/ part of the route makes it clear enough that the routes are for the api. What subdomains like facebook's are doing are pointing to a completely different application, and different web servers. For example, a company may have domains like mail.company.com, portal.company.com, sso.company.com, that all resolve to the address of different web servers for the different apps they have, but in this case it sounds like you are running one web server which is fine, you can have one web server be the api as well as serve the website.

Related

How do I redirect traffic from a domain on other servers to content on mine?

Here's the basic situation:
I have an application on AWS which needs to serve assets to and create 'share' links for content hosted on my AWS servers. I need to figure out a way to still use the URL/domain from another clients infrastructure, so it will essentially whitelabel our application as coming from their services. I was thinking of using Route53 and a CNAME, but things like the dynamic 'share' urls will create a huge problem for redirects. Does anybody have any ideas on how this could be accomplished?
I think that you will have to set up your server at the "whitelabeling" location to have a web server that can call the other URLs and return their content. Ie, you create a server that responds at whitelabel.com, which then calls myAWS.com and passes the result back to whoever called whitelabel.com. You could make this flexible by allowing whatever the end destination URL needs to be to be passed in as a parameter (so, if you call whitelabel.com/foo, it will call myAWS.com/foo), though this has some security ramifications, and also requires a lot of knowledge by the consumer of exactly where things will reside.

Put a subfolder onto a different server with CNAME

Here's the situation. Website.com is an ASP site which needs a blog that is to be Wordpress. So the website.com/blog needs to be hosted onto a php-friendly server. The company hosting the ASP site doesn't want to have anything to do with Wordpress so we have to use some of the shared hosting providers.
How do I have the Blog section placed onto an entirely different server? I've heard this is done with CNAME, but I've never used it. Most of the research I've done revolves around subdomains, but I need a subfolder mapping, and there's not much to read about putting subfolders onto different servers with a different IP and everything.
Thanks.
There are a few different options:
you can bring the traffic to your own server and then redirect to
the correct location
you can bring the traffic to your own server and then proxy it to the correct location
you can direct the traffic to the correct location either via full page or an IFRAME type mechanism
Each option has some benefits and drawbacks depending your devs knowledge level and your infrastructure. Regarding subdomains, you could use a combination approach where you, for example, use subdomain.yourdomain.com to point to a server instance (can be the same server or a totally different one) that maps the subdomain.yourdomain.com name to a specific path, usually via Host header.
A CNAME is a function in DNS that says "Whatever thing you wanted to find for this name, use the same thing for that other name instead". When you're working with web stuff the "thing" in there is nearly always an IP address.
That is, what a CNAME can do for you is to say that when a user's web browser tries to look up the IP address for website.com, it will use the IP address for someotherwebsite.com. Note the total absence of anything web-related, like subfolders, in this. CNAMEs work on whole domain names, nothing else. Since you want to serve only a part of the stuff at a particular name from another server, CNAME cannot help you. CNAME is the wrong tool for you problem. Do not taunt happy fun CNAME.
In order to serve website.com/blog from another server than website.com, you pretty much have to do some sort of reverse proxying (where the ASP site's server relays requests between the user and the Wordpress server). It's probably easier and more robust to give the Wordpress site its own name (blog.website.com or something), and redirect to that from website.com/blog, but only you can know if that's politically possible in your case.

Domain name point to subdomain of a entire different domain

I am completely confused the last few days with this and I still haven't found an outcome that's worked.
Basically I have a domain name without hosting at letshost.ie which is dublinplasterer.ie
I also Have one domain & hosting with godaddy for domain- shanafagan.com which is my own site for web/graphic design service.
I created a subdomain= dublinplasterer.shanafagan.com and uploaded the site files.
Basically I want for example when someone types in dublinplasterer.ie in the address bar if goes to dublinplasterer.shanafagan.com but doesn't show dublinplasterer.shanafagan.com url, stays as dublinplasterer.ie
Im not even sure if this can be done at this stage. head is melted
shanafagan.com and the subdomain dublinplasterer.shanafagan.com have the same ip so how will that work if changing dns?
Any help would be greatly appreciated , am so stuck at this stage.
If you wanted to do it this way you would need a web server for domain2.com
Search for ProxyPass.
The way you should do this is add a second domain on your web hosting (cpanel for example) and point the other domain to this web server.
If you are struggling I recommend using a solution like cPanel that is widely used and simplifies much of the process. It is common enough you can google most issues.
So normally you would have started by making an add-on domain (instead of a subdomain) which would also create it's own subdomain anyway. To do that, you go to your cPanel in GoDaddy and find add-on domain, then make it "dublinplasterer.ie" (Don't add www. to it. Even though this name is hosted elsewhere, we will later go to your DNS files at that hosting and point it to your GoDaddy's name servers and this add-on helps it direct to the right root folder) then choose your local root folder for that site (I think you can actually make this the same as your other subfolder already hosting your files and then it will just pull the same site) or you can pick a different subfolder and then make the add-on domain. This tells any request to this name server that if it is a request for "dublinplasterer.ie" it needs to send it to the subfolder you specified.
If you don't make the subfolder the same as the one you already made, you can either load the same content into your new subfolder or create a CNAME record telling this add-on to point to your subfolder instead but that is more complex so go with the other route.
Lastly, you need to go to your original hosting at letshost.ie and under your domain name find the DNS records tab. Change the name servers to match your GoDaddy ones and now (may take a day or two to show as DNS changes often take days and can't be seen immediately but you can try using a different device/computer/mobile that hasn't loaded it previously to see if it will refresh the correct dns) it should work. Even though it points to your main site name servers, the add-on domain you made receives it and directs it to the subfolder you specified on the add-on domain.
Hope that helps, let me know if it works for you.

How to display content from another domain by editing CNAME records?

I have a site that lets people have their own e-stores, for ex- mysite.com/clientname
What I want is, if somebody opens store.clientname.com or clientname.com/store, the content is pulled from mysite.com/clientname. [ So that their users feel that they are browsing on their site ]
I know this is possible because site'e like tumblr let you do that by changing a CNAME entry for your domain to their IP address.
I do have a dedicated IP address.
Also, can this be done by editing the .htaccess file at clientname.com, and if yes, which method is better/easy?
You'll want to solve the problem in a completely different way for http://store.clientname.com/ versus http://clientname.com/store.
In the first case, you can serve the web site as a virtual host. Just set up a virtual host called store.clientname.com and set its DocumentRoot to be the existing directory that contains the files for http://mysite.com/clientname. If you have other web server configuration directives that apply to http://mysite.com/clientname then you'll also want to apply those in the virtual host. Finally, the client can set up a CNAME record in DNS for store.clientname.com pointing to your web server.
If you are using Apache, you can also use a default virtual host and mod_rewrite to dynamically translate URLs of the form http://store.{whatever}/ to http://mysite.com/{whatever}/. However, this won't work if you are using HTTPS.
In the second case, you don't want to serve the web site at http://clientname.com/ because the client presumably is already hosting that and presumably http://clientname.com/otherstuff has to continue working and come from their server. So the second case is easier for you because all the work has to be done on the client's web server. But it's simple: they will just have to configure their web server to proxy http://clientname.com/store to http://mysite.com/clientname.

Sharing single application across a 2 subdomains in IIS7

I have an application that is currently deployed (ex. www.example.com ). However, now we have a "secure" subdomain, which will take all of the requests that need to be encrypted (ex. secure.example.com). The site that is at www.example.com is currently mapped to C:\inetpub\example.com\wwwroot\, and I've mapped secure.example.com to C:\inetpub\example.com\wwwroot\secure.
However, since secure.example.com was setup as a new website within the IIS Manager, when the secure site is visited, it displays an error since there is no web.config associated with this website; however, this is the way I want it since I want this to be a part of the application that is in the parent directory.
I think what you really meant to do was just right click on the web site for example.com and edit the bindings. In there you can add host names to that site.
Make sure you add them for port 443 which is SSL.
Map both the IIS virtual directories/web sites to the same directory, and check that are both using the same IIS application name.
(Not tried this, but can't recall seeing anything to say it would not work.)

Resources