Jump to content

[SOLVED] How do they do it?


HoTDaWg

Recommended Posts

on websites such as firecold.com or even forums; how is that each user kind of has their own page on the site. For example, if i was to sign up as the username hotdawg on a forum, how is it that when someone views my profile the address is:

http://www.example.com/profiles/hotdawg

rather than

http://www.example.com/members.php?username=hotdawg

or even

http://www.example.com/profiles/?username=hotdawg

 

How do you do that? is a separate page created for the user when they register?

 

any information on this subject would be very useful

 

HoTDaWg

 

 

Link to comment
Share on other sites

.htaccess with modrewrite.

 

Basically you look for profiles keyword and than pass that to the file /profiles.php?user=hotdawg.

 

 

Look at the mod_rewrite for SEO friendly urls, that should explain everything Google.com should provide you with plenty of explinations.

 

Link to comment
Share on other sites

Yep, I will post it later tonight for you for the whole forum to see and reference if need be.

 

But if you need it sooner, google is really your best friend. That is how I got my information =) But it is always good to see a real world example.

 

Currently it is how my site

 

http://www.aeonity.com  is done (ie if you go http://www.aeonity.com/frost it is the same as http://www.aeonity.com/blog.php?username=frost)

 

Great tactic for SEO. =)

 

Link to comment
Share on other sites

The process/index.php is very messy and I do know there is a better way to handle it in the .htaccess using regexp. But at the time this worked and still does work for me. One of these days I am going to do a test and see if one processes faster, if so I will switch to that method. Here is the process/index.php code:

<?php
###############################################
#		Aeonity Blog Code
#		File: process/index.php
###############################################
$path = "../";

include($path . "config.php");

// Check if the we are going to an actual page.
if(file_exists($_SERVER['DOCUMENT_ROOT'] . $_SERVER['REQUEST_URI']) && ($_SERVER['SCRIPT_FILENAME'] != $_SERVER['DOCUMENT_ROOT'] . $_SERVER['REQUEST_URI']) && ($_SERVER['REQUEST_URI'] != "/")) {
$url = $_SERVER['REQUEST_URI'];
if (strstr($url, "articles") && !strstr($url, ".php")) {
	$url .= "/index.php";
	chdir($path.'articles');
}

include($_SERVER['DOCUMENT_ROOT'] . $url);
exit();
}

// Since we know they are entering SEO data lets figure
// out what to display to the user
$url=strip_tags($_SERVER['REQUEST_URI']);

if ($url != "") {
// this will get all the parameters (IE: /user/frost) into an array.
$vardata = explode('/', substr($url,1));
$num_param = count($vardata);

// We do not count the first parameter for 
// our num_param as that is usually a page,
if ((($num_param - 1) % 2) == 0 && ($num_param - 1) != 0 && strstr($vardata[0], ".php")) {
	// Remove/save page for later uses
	$page = $vardata[0];
	array_shift($vardata);

	// Put all variables into GET form for the actual page
	for ($i = 0; $i < $num_param; $i+=2) {
		if ($vardata[$i] != "") {
			$key =  strtolower($vardata[$i]);
			$_GET[$key] = strtolower($vardata[($i+1)]);
		}
	}

	// Make sure we are going to a page that exists
	if (!file_exists($DOCUMENT_ROOT . "/" . $page)) {
		//missingLog();
		Header("HTTP/1.1 404 Not Found");
		include(SERVER_URL . "/missing.php");
		exit();
	}else {
		include($DOCUMENT_ROOT . '/' . $page);
		exit();
	}
}else {
	// Check to see if this is a real DIR or not
	if (!is_dir($vardata[0]) && $vardata[0] != "") {
		// Gather up parameters to give data to page.
		if ($vardata[0] == "articles") {
			chdir($path.'articles/');
			$_GET['articleID'] = $vardata[1];

			if ($vardata[1] == "xml") {
				$page = "xml.php";
			}else {
				$page = "showarticle.php";
			}

			if (count($vardata) == 1) {
				$page = "index.php";
			}

			require($path . "articles/" . $page);
			exit();
		}

		$params = "blog.php";
		$_GET['user'] = $user = $vardata[0];
		array_shift($vardata);
		if ($user == "blog" || $user == "blogs") {
			$_GET['id'] = $vardata[1];
			unset($_GET['user']);
		}else {	
			if (is_numeric($vardata[0]) && count($vardata) == 1) {
				$_GET['secid'] = $vardata[0];
			}else {	
				// If it is one of these we want to direct to
				// a different page.
				switch (strtolower($vardata[0])) {
					case "profiles":
					case "profile":
						$params = ereg_replace("blog.php", "profile.php", $params);
						array_shift($vardata);
					break;

					case "friend":
					case "friends":
						$params = ereg_replace("blog.php", "friends.php", $params);
						array_shift($vardata);
					break;

					case "archives":
					case "archive":
						$params = ereg_replace("blog.php", "archive.php", $params);
						array_shift($vardata);
					break;

					case "rss-feed":
						//$params = ereg_replace("blog.php", "rss.php", $params);
						//array_shift($vardata);
						$_GET['user'] = $user;
						include($path . "rss.php");
						exit();
					break;
				}
			}
			if ($user == "error") 
				$params = "error.php";

			// Get a new parameter count, and populate the parameters with correct data.
			$num_param = count($vardata);
			if ($num_param > 0 && ($num_param % 2) == 0 ) { 
				for ($i = 0; $i < $num_param; $i+=2) {
					if ($vardata[$i] != "") {
						$key =  strtolower($vardata[$i]);
						$_GET[$key] = strtolower($vardata[($i+1)]);
						// if it is for the error page there is no user involved.
						/*if (strstr($params, "error.php?") && $i == 0) {
							$params .= "$key=" . strtolower($vardata[($i+1)]);
						}else {
							$params .= "&$key=" . strtolower($vardata[($i+1)]);
						}*/						
					}
				}
			}else {
				if ($params == "blog.php" && count($vardata) == 1) {
					// This is the keyword-url
					$_GET['keyword_url'] = strtolower($vardata[0]);
				}
			}
		}
		//debug($path . "<Br />" . $params);
		include($path . $params);
		//exit();
	}else {	
		// Chances are this is a bad file, so send to 404 or index.
		if ($vardata[0] != "" && $vardata[0] != "articles") {
			//missingLog();
			//Header("HTTP/1.1 404 Not Found");
			include(SERVER_URL . "/missing.php");
		}else {
			include($_SERVER['DOCUMENT_ROOT'] . $url . "index.php");
		}
		//exit();
	}
}
}


?>

 

Here is the .htaccess code

 

php_flag session.use_trans_sid off
#php register_long_arrays "on"
Options +FollowSymLinks

RewriteEngine on

#I do this for cookie reasons, plus I like the www. better=)
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=permanent,L] 

# These are folders I do not want processed by a file
RewriteRule   ^articles/admin/*.*$  - [L]
RewriteRule   ^cgi-bin/*.*$  - [L]

# If the request is not of the following extensions, process through the process/index.php
RewriteRule !\.(gif|jpg|png|css|pdf|doc|php|swf|inc|ico|js|cgi|wmv|mpg|mpeg|avi|mp3|midi|rar|zip|scr|phps|txt|msi|xml)$ /process/index.php

 

Like I said I think there is a better way to do it using Regex in .htaccess but this way works and I do not know if there is a processing difference.

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.