Website url formats

Discussion in 'HTML & Website Design' started by fadetoblack22, Oct 1, 2008.

  1. #1
    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
     
    fadetoblack22, Oct 1, 2008 IP
  2. steelfrog

    steelfrog Peon

    Messages:
    537
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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?
     
    steelfrog, Oct 1, 2008 IP
  3. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #3
    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):
     
    Clive, Oct 1, 2008 IP
  4. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #4
    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.
     
    fadetoblack22, Oct 1, 2008 IP
  5. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #5
    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.
     
    Clive, Oct 1, 2008 IP
  6. Gremelin

    Gremelin Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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/
     
    Gremelin, Oct 1, 2008 IP
  7. SEOpaw

    SEOpaw Peon

    Messages:
    437
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #7
    SEOpaw, Oct 1, 2008 IP
  8. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #8
    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.
     
    fadetoblack22, Oct 2, 2008 IP
  9. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #9
    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?
     
    Clive, Oct 2, 2008 IP
  10. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #10
    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>
     
    garrettheel, Oct 2, 2008 IP
  11. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #11
    Its going to be every url on the page. contact was just an example.
     
    fadetoblack22, Oct 2, 2008 IP
  12. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #12

    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
     
    fadetoblack22, Oct 2, 2008 IP
  13. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #13
    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"
     
    garrettheel, Oct 2, 2008 IP
  14. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #14
    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):
     
    Clive, Oct 2, 2008 IP
  15. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #15
    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.
     
    garrettheel, Oct 2, 2008 IP
  16. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #16
    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.
     
    fadetoblack22, Oct 2, 2008 IP
  17. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #17
    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.
     
    Clive, Oct 2, 2008 IP
    fadetoblack22 likes this.
  18. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #18
    That's already what I said -_-

    And I'm assuming it's being used on more then just a few links.
     
    garrettheel, Oct 2, 2008 IP
  19. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #19
    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.
     
    fadetoblack22, Oct 2, 2008 IP
    Clive likes this.