SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru pinch's Avatar
    Join Date
    Mar 2005
    Posts
    688
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Maintaining Absolute Links

    In keep with SEO practices I'm trying to ensure that all of my hyperlinks are absolute. In order to do this, I've been assigning the NavigationURL property of my HyperLink controls in the code-behind:

    Code ASP:
        protected void Page_Load(object sender, EventArgs e)
        {
          if (!IsPostBack)
          {
            hlRankingsThroughImage.NavigateUrl = (this.Page as BP.CheatSheetWarRoom.UI.BasePage).BaseUrl + "FantasyFootball/FootballPlayerRankings.aspx";
          }
        }

    I could just use plain html instead of HyperLink controls, but assigning the NavigationURL in code means that it will work both on my local machine and the server without and coding change. Still, it's a bit of a pain to keep track of all the URLs in the code behind. Is there any way to programmatically assign an absolute NavigationURL in the .aspx page?

  2. #2
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code ASP:
            hlRankingsThroughImage.NavigateUrl = "~/FootballPlayerRankings.aspx";

    will do. Any server control that takes an uri will translate ~ to mean the virtual root directory.

  3. #3
    SitePoint Guru pinch's Avatar
    Join Date
    Mar 2005
    Posts
    688
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by honeymonster View Post
    Code ASP:
            hlRankingsThroughImage.NavigateUrl = "~/FootballPlayerRankings.aspx";

    will do. Any server control that takes an uri will translate ~ to mean the virtual root directory.
    Yeah but it still isn't an 'absolute' link when generated, which is what I was trying to accomplish (for SEO reasons).

  4. #4
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    That's a new one--why would absolute links matter for SEO purposes?

  5. #5
    SitePoint Guru pinch's Avatar
    Join Date
    Mar 2005
    Posts
    688
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wwb_99 View Post
    That's a new one--why would absolute links matter for SEO purposes?
    From the Sitepoint SEO FAQs

  6. #6
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Interesting. Well, I would skip that one myself. I have been using purely relative links for years and never had an issue with crawlers not being able to follow anything. I also have a google mini, and it can definitely follow relative links. This one goes in the "not worth the pain" category IMHO.

  7. #7
    SitePoint Guru pinch's Avatar
    Join Date
    Mar 2005
    Posts
    688
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wwb_99 View Post
    Interesting. Well, I would skip that one myself. I have been using purely relative links for years and never had an issue with crawlers not being able to follow anything. I also have a google mini, and it can definitely follow relative links. This one goes in the "not worth the pain" category IMHO.
    Fair enough, I can live with that.

  8. #8
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The absolute links can do more than SEO, they also confuse some of the dumber recursive content scrapers (i know that sounds stupid, but its true lol).

    this is what I used
    Code:
      string workingDir = Server.MapPath(""); // + "\\somefolder" optionally
    I used it in an app that deployed a site using static *.html pages.. so it would be a little different for you, as you'd need to append "\\folder" each time you step into a directory. For me the folder names were in SQL as the entire dataset was designed for deployment (it was a wiki). There's probably a way to programatically access that information but I cant think of it off the top of my head. If you want to brute force it, parse the the uri/url.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •