I am designing my website, but it also has a subdomain. The main site, lets say. Cat.com has urls like this at the moment. e.g. <a href="contact.php">contact</a> On the subdomain however, which is kitten.cat.com that shows up as. <a href="kitten.contact.php">contact</a> and it does not find the page. I could use the url as home/public_html/cat.com/contact.php, but I have never seen that used before and it is a bit of a security risk posting the full path. I could also use http://www.cat.com/contact.php, but I don't like that method. The other option is to duplicate all my files in the subdomain folder which I don't want to do because any changes will have to be made twice. What is the best option here? thanks
I'm not sure I understand what the problem is; what you're saying is that the links break when you move your files to the sub-domain?
I don't think something like that should be happening at all in the first place. Doesn't look like possible to me. Anyway, try using something like <a href="/contact.php">contact</a> Code (markup): or <a href="./contact.php">contact</a> Code (markup):
Yes the links break on the subdomain. Its actaully like this: contact.php changes to kitten.cat.com/contact.php and of course, it can't be found there. "Clive", to do what you said, I have to make the path look back into my domains list and then forward into my subdomain list. This is not the sort of info I want to be posting in my link urls. I did actually try this to start with and it didn't work for the stylesheet for some reason.
If contact.php is not a page of the website hosted on your current subdomain then you will need to include the full URL in the link, relative path won't work simply because the page you're linking belongs to a different site. And yes, I was right about kitten.contact.php being a typo.
If you're linking to a page on a subdomain, generally you'd have to list the full URL as the subdomain is treated as a seperate entity. So, main site "cat.com" would be: contact.php http //kitten.cat.com/contact.php And visa versa: contact.com http //www.cat.com/contact.php I'd advise against using subdomains however as they're treated as seperate entities; so search engines, cookies, etc will treat them as such; instead I'd recommend using folders under the parent site: http //www.cat.com/kitten vs http //kitten.cat.com/
I'm still not sure what to use. I don't think I've ever seen a site link to its stylesheet using a absolute url.
Lots of them do. For instance, check any wordpress powered website. The stylesheets are linked to by absolute URL's. Anyway, we are talking about linking to a contact page, not a stylesheet, right?
Simply store the url of your site in a variable and use that in your links, for example: <a href="cat.<?php echo $mysite; ?>"></a>
That could be what I need, but that gives. cat.cat.com What I need is more like: <a href="<?php echo $mysite; ?>/contact.php"></a> But that still comes out as kitten.cat.com/contact.php
No, you're missing the point. I meant that you keep "cat.com" in the variable, then whenever you want to use the sub-domain, you can just say "kitten." . $mysite; which would produce "kitten.cat.com"
I'm not getting it. What stops you from simply using <a href="http://www.cat.com/contact.php">Contact Form on the Main Site</a> Code (markup):
That's for regular links without the subdomain... and in that case, I'd just use a relative link. I was referring to links with the subdomain. Using a variable makes it easy to update the links if the domain changes. Hardcoding a lot of links like that in is a stupid idea.
I will just use absolute links on the subdomain then. If I have a stylesheet and am calling it to a subdomain with an absolute link and the stylesheet has relative links in it. e.g. /header.jpg, then will this be found? I think it will, but I'm not sure.
Well this is where I started: So I assumed the following picture: fadetoblack22 has got a main website, and a second one which uses a subdomain. He wants to have a single contact form which is located on the main site, so he wants a way to link to it. He MUST use an absolute URL in this case. No, you couldn't. That is an incorrect method since it's rather a full path to the file on the server, not a web link. You have to accept it. Best you can do is set up a PHP variable like $url = 'http://www.cat.com'; PHP: And then reference it in the files whenever an absolute link to the main website is required, (although it doesn't really make much sense if you plan to use it on 2-3 links only...) like: <a href="<?php echo $url ?>/contact.php">Contact Us</a> Code (markup): Oh wait, does your webhost use cPanel control panel? If so, then for each of your subdomains it assigns a subfolder inside the main domain's root directory, that's true. As a result, your main website can use the files that belong to the subdomains. The other way round is NOT possible however.
Thanks for the help. I will have to use absolute links then. There is quite a lot because it is the whole structure of the site. Plus it is calling php includes from the main that have relative links, so they then don't work. It is cPanel, but the main site is an addon domain and the subdomain is a folder along side it rather than in it.