Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts

    Problem displaying rewitten URLs as rewritten

    Hi all, I have re-wrote my URLs with the .htaccess to be more user friendly. Currently I have:

    domain.com/user/UserName

    If I have a user called "UserName" this URL works how you would think.

    But because these pages have variables I seem to have a problem with displaying the links to the user page to the clients. Obviously I can't write a static link as that will only ever link to one user. Currently I use something like this to have a link to a logged in persons own user page from the header of the site:

    domain.com/userinfo.php?user=$session->username

    with my rewrite rule looking like this:

    RewriteRule ^user/([^/]*)$ /userinfo.php?user=$1 [L]

    So, the problem is the link they press still looks like:

    domain.com/userinfo.php?user=UserName

    I am wondering how I can make it so it will display a link to click that is rewritten like the first example?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Obviously I can't write a static link as that will only ever link to one user.
    So, the problem is the link they press still looks like:

    domain.com/userinfo.php?user=UserName
    Can't you just change that link to the format
    PHP Code:
    domain.com/user/{$session->username
    ? (Sorry, if I didn't get the issue.)
    Last edited by abduraooft; 07-31-2010 at 05:07 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Custard7A (07-31-2010)

  • #3
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    Oh, brilliant, what a simple oversight. I guess I was somehow thinking the rewrite would convert all links without me changing that. Well, many thanks, another valuable lesson learned.

  • #4
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    I do have one problem with it still; when on a user page and I click on the header link to the users own profile, laid out like:

    domain.com/user/{$session->username}

    It comes up as

    domain.com/user/user/UserName

    That is of course an invalid link and just gives a 404. How can I fix that? If someone knows the answer here?

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    PHP Code:
    echo "<a href=\"/user/{$session->username}\">{$session->username}</a>"
    or

    PHP Code:
    <a href="/user/<?php echo $session->username;?>"><?php echo $session->username;?></a>
    or
    PHP Code:
    echo '<a href="/user/'.$session->username.'">'.$session->username.'</a>'
    Last edited by abduraooft; 07-31-2010 at 05:15 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Custard7A (07-31-2010)

  • #6
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    Works great now, thanks again abduraooft. I guess it was just how I'd wrote the link out.


  •  

    Posting Permissions

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