SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    another mod rewrite question

    the real page is: /dir/index.php?id=1
    I want it to go to: /newdir/page-title/

    I have this working. My question is about the actual link on the referring page.

    Without mod rewrite, this will be <a href="/dir/index.php?id=1">click here</a>. So, when the user mouses over the link, that's what they see in their status bar, and that's what's also written into the page. Which also means that Google will index that link. Right?

    What I would rather have is <a href="/newdir/page-title/">click here</a>. But if I have that, don't I lose the id in the link?

    Hopefully this made sense.
    How do I overcome this?

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    tg,

    Yes, that's how it works. YOU have to create the links the way that you want them seen and leave it to mod_rewrite to fetch the proper file.

    If you "have this working," what's the problem? I'm sure it'll work fine for id=1 (hardcoded into the mod_rewrite) but for other values, you'll need to use other code. http://wilderness-wally.com uses the page titles to fetch the articles out of the database as well as creating the links in a rather lengthy TOC - the id=1 is only used for the default Home Page which is "Welcome." In other words, it can be done but NOT by trying to convert a title into an id (title must be unique in the db and you need to pay careful attention to converting spaces and not allowing characters not allowed in URIs).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    tg,

    Yes, that's how it works. YOU have to create the links the way that you want them seen and leave it to mod_rewrite to fetch the proper file.

    If you "have this working," what's the problem? I'm sure it'll work fine for id=1 (hardcoded into the mod_rewrite) but for other values, you'll need to use other code. http://wilderness-wally.com uses the page titles to fetch the articles out of the database as well as creating the links in a rather lengthy TOC - the id=1 is only used for the default Home Page which is "Welcome." In other words, it can be done but NOT by trying to convert a title into an id (title must be unique in the db and you need to pay careful attention to converting spaces and not allowing characters not allowed in URIs).

    Regards,

    DK
    thank you.

    Yeah, I already have my site working this way. Unfortunately, since it's a user-contributed site some of the titles are duplicating. I thought I had all of that sorted out, but some of it got past me. I was just hoping there might be a way to do the title AND id thing. Call me a dreamer...

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    tg,

    You CAN but only if you use both in the URI links - and use their id to access the article (the title would be "throw away").

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    tg,

    You CAN but only if you use both in the URI links - and use their id to access the article (the title would be "throw away").

    Regards,

    DK
    what would the link look like? Wouldn't it be /dir/index.php?title=title&id=1 ? That defeats the purpose, no?

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    tg,

    Yes, THAT would defeat the purpose.

    YOU have to decide how you want the URI to look and create the links in that format. Then YOU have to create the mod_rewrite to redirect from the links you've created to what Apache can serve.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •