Jump to content

Domain name


vchris

Recommended Posts

I have 1 server with 2 websites on it. One is on the root of the server and the other is a sub directory. We have a domain name which we would like to point to the sub directory. Now this guy that has the domain name is saying that he cannot point the domain name to the sub directory, only the server (root site) and that I should be able to have it redirect to the sub directory. Isn't he supposed to be able to point anywhere with his domain name? If not then how do I redirect to the sub dir, since some users will want to go to the root site and others (with that domain name) will want to go to the sub dir site.

Link to comment
Share on other sites

It's possible, but it's not very easy to map it like you describe. It requires some twingling with the server and DNS' configurations. Something which could be made even harder on shared hosts.But doing the redirect is easy. In PHP, check the $_SERVER['SERVER_NAME'] variable, and send header('Location: ...'); based on it.Keep in mind that redirects decrease perofmance, so what you might want to do instead is do "chdir('the subfolder')" to change the folder PHP is running from the actual subdirectory, and then "include_once 'the other php file.php';" to actually perform whatever action you wanted to initially do.

Link to comment
Share on other sites

This is ColdFusion but shouldn't be too different. So basically in my /index.cfm page I would have to check the Server Name and redirect appropriately right?

Link to comment
Share on other sites

This is ColdFusion but shouldn't be too different. So basically in my /index.cfm page I would have to check the Server Name and redirect appropriately right?
Yes. Or (again after looking up the server name) include the other cfm file, ensuring the context by which relative paths are resolved is also changed to the subdirectory.
Link to comment
Share on other sites

I am not understanding you completely. When pointing a domain you cannot specify what directory to point to, only the server (IP or name server). Apache or IIS handles pointing the different domains.Do you have control over the web server?

Link to comment
Share on other sites

You're looking for something like this:

<!--- redirect for yourdomain.com ---><cfif cgi.http_host CONTAINS "yourdomain.com"><cfheader statuscode="301" statustext="Moved permanently"><cfheader name="Location" value="http://www.yourdomain.com/yoursubdirectory/"><cfabort>

But that in the Application.cfc of each site (modified respectively) and you will be fine. If either site is static HTML then you will have to do this on the server itself. With Apache, you would use the .htaccess file but in windows you would need access to IIS and then define Host Headers to accomplish this. I have 13 websites running on one hosting account note the "/i/" when you go to http://www.iribbit.net.For what its worth, domain name can only be pointed to an IP address. Unless you are able to assign a subfolder a unique global IP, you will only be able to redirect the user the way I've stated above.

Link to comment
Share on other sites

I am not understanding you completely. When pointing a domain you cannot specify what directory to point to, only the server (IP or name server). Apache or IIS handles pointing the different domains.Do you have control over the web server?
If he has, Apache (I don't know about IIS) can be adjusted to serve a diferent folder based on the domain name by which you reached it. THAT is how he could do it. But as I said, it requires tweaking to the server and he's not likely to have those rights.
Link to comment
Share on other sites

I'm not quite sure about the web server and I don't have any access to it. I'll be using skemcins method. If they can activate the domain name this week. This site goes public (no password) on monday, yes next monday (dec 10th). Government is so slow omg.

Link to comment
Share on other sites

Skemcin: Your code seems to be working well. The site is not live yet, probably tomorrow but I tested it. I had a question, what does <cfheader statuscode="301" statustext="Moved permanently"> mean? I was wondering if I needed this line in my cfelse.

Link to comment
Share on other sites

I probably forgot to mention this but our server is a virtual server (shared by many users). This created a bit of a problem this morning when trying to set up the domain name. I had an error 400 - bad request but called my host and it works. Now for the redirection, using cgi.http_host doesn't give my the new domain name, it gives me the default one from my host since it's a virtual server. Using cfdump, I don't see any cgi variable that contains what I need. I currently have a javascript redirecting, since it's browser side, I get the correct window.location.href value. We are probably going to swap our 2 sites so we won't need to redirect but if there is an easy coldfusion fix to the redirection let me know.

Link to comment
Share on other sites

Skemcin: Your code seems to be working well. The site is not live yet, probably tomorrow but I tested it. I had a question, what does <cfheader statuscode="301" statustext="Moved permanently"> mean? I was wondering if I needed this line in my cfelse.
Even though I don't know much ColdFusion, I can guess this sends an HTTP header, which as by the rest of the attributes is the status code 301, used for redirection, and the status text, which honestly, I don't know what is used for (I believe UAs use the status codes, not the messages, right?).It's identical to saying something like:
Redirect permanent /index.cfm /subfolder/index.cfm

in .htaccess files.

Link to comment
Share on other sites

Except that it depends on the url entered by the user. I need to know what the user wants to access. Does he want to access the root website or the subroot website? The .htaccess wouldn't be able to know that right? I'd rather use a .htaccess file than javascript.

Link to comment
Share on other sites

The 301 header should be used for redirection, but most user agents and servers have been using 302 instead, which I believe is "found". They send a 302 header followed by a location header, and the browser sees the 302 and uses the location header to figure out where to redirect to. If you use a proxy or something that lets you view HTTP headers and you just sent a location header in PHP, or you use response.redirect in ASP, you'll see a 302 followed by a location header.

I need to know what the user wants to access. Does he want to access the root website or the subroot website? The .htaccess wouldn't be able to know that right?
Servers that are set up with multiple sites use the host header to tell it which site to load. You should be able to rely on the browser always sending a host header. We have a server set up here that probably has 30 sites on a single IP, and it uses the host header. That's how you set it up in IIS at least, you can probably use .htaccess to check the host header. The host header should include the full host that the user is trying to reach, so any subdomains will be in the host header as well. Most of the sites our server has set up are subdomains on our main domain that each get directed to their own folder in wwwroot, a few of the sites have their own domains though.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...