6

So I have a DNS domain name for my computer so that I can connect to it easily without remembering my IP address every time and it works great. I also have a website that is being hosted off my computer that I have a domain name for. The domain name has a URL forwarding setting of Frame(cloaking) which points to my website folder.

I have a login part to my website that uses php sessions. When I go on localhost to test the session, it works fine. But when I use my domain name it doesn't work at all. So I tried using my DNS name and putting the folder after it example.tk/MySite. To my surprise it worked. But if I don't type in the /MySite after the DNS name, it goes to the MAMP Index of /. I do not want that at all. I was wondering if it is possible to forward a DNS domain name to a folder. I looked it up and people said no, you have to set up "Virtual Hosting" or what ever. Now I know very very little about all this Domain stuff, so any help at all would be greatly appreciated.

Thanks in Advance!

Where I figured out about virtual hosting.

1
  • DNS is Domain Name System and nothing else, you should read up en.wikipedia.org/wiki/Domain_Name_System. PHP, URLs that's all web related, so webserver should take care of "pointing" to folder on server.
    – alexus
    Feb 2, 2015 at 17:29

3 Answers 3

1

The behavour you observe is exactly as expected. Note that an URL like http://example.tk:80/MySite means that the client has to contact the host example.tk (and only to find out whyich host that refers to is what DNS is used for in this context), then initiate a TCP connection to a server process listening on port 80 of that host, then use the http protocol to request the URI /MySite from example.tk. The typical webserver will interprete such a path-like URI as a path relative to its document root and for exmample return the content of a file of that name (or execute a php script or list the contents of a directory [in fact after a redirection] or whatever you configure).

So since you are almost happy with the result - just off a directory level - I suggest you reconfigure your webserver to serve from a different document root. On the other hand, your report about http://localhost doing the right thing suggests that you already have virtual hosting set uop, i.e., the vhost localhost is configured to use that MySite folder as its document root. It should be possible to modify the configuration of your example.tk host to serve from the very same document root. Maybe start reading through the vhost-specific configuration files of your webserver (probably located in /etc/apache2/sites-enabled or similar). Look out especially for DocumentRoot options, of course.

1
  • When I use localhost, I really type in localhost/MySite not just localhost. Would that change the root level that you were talking about?
    – Ryan
    Feb 2, 2015 at 19:04
7

Q: Can a DNS domain name point to a folder on a server?

A: No.

1
  • Perhaps I'm not saying this correctly, but I thought that a domain name DOES point to a specific folder, normally called "DocumentRoot" on many systems. Dec 12, 2015 at 2:14
0

DNS cannot forward to a folder.

There are some options to solve this a different way.

First, many DNS providers allow you to set up "HTTP redirection" for a DNS name. What's actually happening with this feature is that the DNS is pointing to the provider's web server, where they have a simple web server configuration set up to provide the HTTP redirection portion.

You could use the approach yourself: Point the DNS to a server where you are running a web server that is configured to respond to the same domain name, by either displaying or redirecting to a folder. The details vary significantly based on the details of your situation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .