...

View Full Version : Problem displaying rewitten URLs as rewritten



Custard7A
07-31-2010, 02:41 AM
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?

abduraooft
07-31-2010, 10:15 AM
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

domain.com/user/{$session->username}? (Sorry, if I didn't get the issue.)

Custard7A
07-31-2010, 05:47 PM
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. :)

Custard7A
07-31-2010, 05:57 PM
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?

abduraooft
07-31-2010, 06:07 PM
echo "<a href=\"/user/{$session->username}\">{$session->username}</a>"; or


<a href="/user/<?php echo $session->username;?>"><?php echo $session->username;?></a> or

echo '<a href="/user/'.$session->username.'">'.$session->username.'</a>';

Custard7A
07-31-2010, 06:13 PM
Works great now, thanks again abduraooft. I guess it was just how I'd wrote the link out.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum