Modernvox Posted February 11, 2010 Share Posted February 11, 2010 A lot of people seem to be requesting some help on this, but after spending a few hours searching and reading NO ONE explains how it's done?? So if my site is mysite.com and the members profile page is located at mysite.com/profile How would I take the $username and add it to the end of mysite.com/ RewriteEngine on RewriteRule ^mysite/.com/profiles/.php$ /mysite/.com/$username I know that's wrong, but what would it look like? Thanks in advance guyz Quote Link to comment https://forums.phpfreaks.com/topic/191710-allow-members-to-choose-a-vanity-type-urlseems-no-one-wants-to/ Share on other sites More sharing options...
cags Posted February 11, 2010 Share Posted February 11, 2010 You, like pretty much everyone who turns up here have the process back to front. You make all the links on your site look like the 'pretty one' you then use mod_rewrite to make the URL mean something to the server, allowing it to pass the correct information through to the correct file. For example lets say I acces my profile by using... mysite.com/profiles/cags, the actual file that is loaded when I enter that URL is mysite.com/profile.php?id=cags. The server needs to know how to convert the given URL into the correct URL to serve up. RewriteRule ^profiles/([a-z]+)/?$ /profile.php?id=$1 Quote Link to comment https://forums.phpfreaks.com/topic/191710-allow-members-to-choose-a-vanity-type-urlseems-no-one-wants-to/#findComment-1010711 Share on other sites More sharing options...
Modernvox Posted February 11, 2010 Author Share Posted February 11, 2010 You, like pretty much everyone who turns up here have the process back to front. You make all the links on your site look like the 'pretty one' you then use mod_rewrite to make the URL mean something to the server, allowing it to pass the correct information through to the correct file. For example lets say I acces my profile by using... mysite.com/profiles/cags, the actual file that is loaded when I enter that URL is mysite.com/profile.php?id=cags. The server needs to know how to convert the given URL into the correct URL to serve up. RewriteRule ^profiles/([a-z]+)/?$ /profile.php?id=$1 Ok..That makes sense, but how would I make the link to the users actual profile page if every user has there own name. The variable will be $username of course, but that's not valid format for a url. Or does mod rewrite rule take care of this part by transferring mysite.com/profile/id=4? to mysite.com/$username The profile page is really one page and depending on the info passed will result in it's display i.e. users profile? Sometimes I start really analyzing this stuff and it becomes overwhelming to the point it takes me days to grasp the concept. Quote Link to comment https://forums.phpfreaks.com/topic/191710-allow-members-to-choose-a-vanity-type-urlseems-no-one-wants-to/#findComment-1010892 Share on other sites More sharing options...
cags Posted February 11, 2010 Share Posted February 11, 2010 *sigh* how many times do I need to explain this. Or does mod rewrite rule take care of this part by transferring mysite.com/profile/id=4? to mysite.com/$username It does nothing of the sort, the whole point is to do the exact opposite. You take a URL that is requested, this is a URL that looks nice but is not the valid address of an actual file, you use regular expressions to break it down and send it to an actual file. Thus you take any requests for .com/cags/ and forward it to .com/profile.php?id=cags as my last example explained. The pretty URL, the one used on your site is like a PO box, when the user types it in an address bar, or click a link on your site it simply links to the PO box (.com/cags/). What Apache does is take anything sent to the PO box and forwards it along to the actual address, like a dogsbody/lackey/errand boy. That's all there is to using mod_rewrite for 'pretty urls'. How you use the page .com/profile.php?id=cags to load a profile has nothing to do with it. Quote Link to comment https://forums.phpfreaks.com/topic/191710-allow-members-to-choose-a-vanity-type-urlseems-no-one-wants-to/#findComment-1011022 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.