This is the first add-on of many for the great script found here.
On their forum I noticed several people asking about rewriting the urls to the user’s profiles so after fiddling around I managed to create my first mod for phpmotion.
This will change your member profile links from:
http://www.example.com/memberprofile.php?uid=xx
to
http://www.example.com/user/username
Isn’t that nicer?
Step 1: Editing the .htaccess file
This file should be in the root folder. This is what allows the urls entered to be redirected to the real url’s used by the script.
If you don’t have a .htaccess file in the root simply create one in notepad.
Add this to your file:
RewriteEngine On
<IfModule mod_rewrite.c>
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/(.*)$ memberprofile.php?user=$1 [L]
</IfModule>
Once you’ve done this you can save and close the file, we won’t need it anymore.
Note: You can change ^user/(.*)$ to anything you like but keep the ^ at the beginning and the /(.*)$ at the end.
Step 2: Editing memberprofile.php
You must add this into memberprofile.php as it catches whatever value is behind the / after user and finds the user_id so that it can display the correct page.
$user = $_GET['user'];
if($user){
$sql = mysql_query(”SELECT user_id FROM member_profile WHERE user_name = ‘$user’”);
$row = mysql_fetch_array($sql);
$member_id = $row['user_id'];
}
else{
$member_id = $_GET['uid'];
}
This tells the script to look for the user_id of the username entered in the url and then displays the correct page. It also looks for the user id if there is no user name therefore the original links will still work correctly.
Step 3: Editing the templates
The most annoying part of this add-on is what follows: On every img, href, script, etc… you must either add a / or the variable [var.base_url] like so:
<a href=”[var.base_url]/index.php”>Videos</a> or
<a href=”/index.php”>Videos</a>
This must be done as otherwise the script will look for the files in the wrong directory. I recommend using the [var.base_url] as using full paths is easier in the long run.
And there you go you’ve got easy to remember paths to userprofiles!
If you don’t fancy touching around in the code, I can set it up for 10€ (in under 48hrs)!

0 Responses to “PHPMotion Add-on: Member profile URL rewrite”
Leave a Reply