Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-31-2010, 01:41 AM   PM User | #1
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
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?
Custard7A is offline   Reply With Quote
Old 07-31-2010, 09:15 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
Obviously I can't write a static link as that will only ever link to one user.
Quote:
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.)
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

Last edited by abduraooft; 07-31-2010 at 05:07 PM..
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
Custard7A (07-31-2010)
Old 07-31-2010, 04:47 PM   PM User | #3
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
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 is offline   Reply With Quote
Old 07-31-2010, 04:57 PM   PM User | #4
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
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?
Custard7A is offline   Reply With Quote
Old 07-31-2010, 05:07 PM   PM User | #5
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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>'
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

Last edited by abduraooft; 07-31-2010 at 05:15 PM..
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
Custard7A (07-31-2010)
Old 07-31-2010, 05:13 PM   PM User | #6
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
Works great now, thanks again abduraooft. I guess it was just how I'd wrote the link out.
Custard7A is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:06 AM.


Advertisement
Log in to turn off these ads.