HoTDaWg Posted March 15, 2007 Share Posted March 15, 2007 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 Quote Link to comment Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 .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. Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 15, 2007 Share Posted March 15, 2007 http://meta.wikimedia.org/wiki/Using_a_very_short_URL Quote Link to comment Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 If you still need an example, I can provide my .htaccess file that I usually use available to you. (not for about 6 more hours until I get home) but yea. Quote Link to comment Share on other sites More sharing options...
HoTDaWg Posted March 15, 2007 Author Share Posted March 15, 2007 if you dont mind frost110 could you supply that for me? Thank you all, and there is no rush frost. topic solved, HoTDaWg Quote Link to comment Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 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. =) Quote Link to comment Share on other sites More sharing options...
per1os Posted March 16, 2007 Share Posted March 16, 2007 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. Quote Link to comment 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.