Jump to content

Allow Members to Choose a Vanity type URL..Seems no one wants to.....


Modernvox

Recommended Posts

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

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

*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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.