• [Mod] Search Engine Friendly URLs aka Short URLs 3 0 5 1
Currently:  

Author Topic: [Mod] Search Engine Friendly URLs aka Short URLs  (Read 726955 times)

0 Members and 1 Guest are viewing this topic.

Offline Acidgod

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 2.421
  • It's me?
    • View Profile
    • Flash-Webdesign
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #195 on: December 06, 2005, 02:51:12 PM »
seems that your not allowed to use mod rewrite...

Offline waleed

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #196 on: December 06, 2005, 06:48:20 PM »
everything is ok now  :)

Offline Zyga

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #197 on: December 16, 2005, 07:13:56 PM »
Thx ! Works great   :)

only 2 questions
1.with one version is better this from I page or from 13 (and why)
2 in this moment it works realy nice but what when i change server on new one without rewrite module and without acces to add (activate) this module - what should I change in code ?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #198 on: December 17, 2005, 12:20:14 AM »
1.with one version is better this from I page or from 13 (and why)
it depence on what is that you need ;) if you need only "convert" .php files into .html then first page is better, cause its simplier. But if you decided to add image names to the url, then 13 page would be the answer.
 
2 in this moment it works realy nice but what when i change server on new one without rewrite module and without acces to add (activate) this module - what should I change in code ?
You always should have backups of your files. So, if you change to a server without mod_rewrite available, simply restore the sessions.php from the backup before you modifyed it, and everyting should be alright ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #199 on: December 25, 2005, 10:05:14 PM »
From your sessions.php file,

change :

Quote

$user_profile_link = (!empty($url_show_profile)) ? preg_replace("/{user_id}/", $row['session_user_id'], $url_show_profile) : ROOT_PATH."member.php?action=showprofile&".URL_USER_ID."=".$row['session_user_id'];


to :

Code: [Select]

$user_profile_link = (!empty($url_show_profile)) ? str_replace("{user_id}", $row['session_user_id'], $url_show_profile) : ROOT_PATH."member.php?action=showprofile&".URL_USER_ID."=".$row['session_user_id'];


Merry Christmas.

Offline bibabobu

  • Sr. Member
  • ****
  • Posts: 311
  • Technische und künstlerische Gravuren
    • View Profile
    • Technische und künstlerische Gravuren für die gesamte Metall-, Kunststoff- und Papierindustrie
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #200 on: December 26, 2005, 10:18:47 PM »
@  v@no

Quote
Lets do one step at a time: fix the javascript errors, then if the problem remains, we'll continue troubleshoot.

Dear v@no, now i think i have fixed all my errors on my URL. But my problem with the category jumpbox still exists.
Please try yourself on several pages of my site. On some pages it works and on some it isn't!
I think this problem exists, since i installed this MOD. Also texaholic has this problem if i remember right.

So please do you have advice to fix this problem :?:

Offline Eagle Eye

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #201 on: December 27, 2005, 10:49:10 PM »
Sorry, I am not able to understand this instruction in SEF url mod on page 13 by "lotus69" “first : in sessions.php
find the url function and replace it by :”
what I should lookout to replace (maybe more correct: which code I should replace)

Thanks for this wonderful mod.  8)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #202 on: December 28, 2005, 01:39:02 AM »
You need to find this block of code:
Code: [Select]
  function url($url, $amp = "&") {
    global $l;
    $dummy_array = explode("#", $url);
    $url = $dummy_array[0];

    if ($this->mode == "get" && !preg_match("/".SESSION_NAME."=/i", $url)) {
      $url .= preg_match("/\?/", $url) ? "$amp" : "?";
      $url .= SESSION_NAME."=".$this->session_id;
    }

    if (!empty($l)) {
      $url .= preg_match("/\?/", $url) ? "$amp" : "?";
      $url .= "l=".$l;
    }

    $url .= (isset($dummy_array[1])) ? "#".$dummy_array[1] : "";
    return $url;
  }
And replace it with what they posted.

P.S.
Just in case you didnt know, see a gray icon next to the each reply headline? if you move your mouse cursor over it, right click and choose "copy url" ("copy shortcut" or "copy location" whatever is in your browser), then you can post that url when you are referring to a specific reply and make it easier for others to find it ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Eagle Eye

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #203 on: December 29, 2005, 06:02:22 PM »
Thanks V@no

I never notice it, thanks for hinting it out… :D

I know that this  http://www.4homepages.de/forum/index.php?topic=6729.msg53658#msg53658 mod is difficult but the results that can be archived is compelling me to try it….

I have successfully modified all the steps expect step 2 and step 4
hope someone could make these steps a bit more easy  :(

In step 2 for $site_sess->url(ROOT_PATH."details.php?" added this $image_name in the highlited area,

but for $site_sess->url(ROOT_PATH."categories.php?" what should be added and where?

and in step 4

I just replaced

$link_arg = $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$cat_id);
with

$link_arg = $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$cat_id,0,$cat_cache[$cat_id]['cat_name']);

well the results are that; 
if i am clicking on a image from random image with file name 82 and image name lc, this is  what i am getting http://mysite.com/image-lc,82.html

and categories are
http://mysite.com/categorie-,1.html

but nothing open in this urk, just a 404 error

 :cry:

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #204 on: December 30, 2005, 01:21:05 AM »
The third parameter they mean the third parameter of the function.
the parameters are separated by comma. like this:
$site_session->url(param1, param2, param3)
So if you find the needed line, check how many parameters already supplyed. if only one, then after first parameter add:
, 0, $image_name
In some cases the second paramater already supplyed (something like , "&") , then all you need to add is:
, $image_name
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline shaqman1

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #205 on: January 02, 2006, 04:48:40 AM »
this mod is interesting, but i was wondering if it could be taken a step furthur. with this mod a url like this: http://www.website.com/details.php?image_id=8 would turn into this http://www.website.com/img8.htm.

But I was wondering if I could turn this url: http://www.website.com/details.php?image_id=8 into http://www.website.com/Ferrari, assuming my image name is Ferrari. Is that possible, or is that just a dream I am dreaming of?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #206 on: January 02, 2006, 05:50:30 AM »
scroll back a few pages, atlest start reading from the middle ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline shaqman1

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #207 on: January 02, 2006, 06:19:09 AM »
scroll back a few pages, atlest start reading from the middle ;)

oh ok lol.. so i can't do what I wanted to do.

well...i use 4images for one of my sites and its awesome, but for my other site (which is not an image based site, but a video based site) i don't really think its nessessary, however i wanted to be able to use the ratings feature. ratings is really the reason for me wanted to use 4images for a non image site.

Is their any way I would be able to rate my files (like a .wmv or a .rm file) without have to be in the 4images gallery. Like could I implement that ratings feature on a page like "http://www.site.com/Food.php" instead of from "http://www.site.com/details.php?image_id=7883".

Even if I could do that without 4images that could be great. Thanks for the help!

Offline kief24

  • Sr. Member
  • ****
  • Posts: 267
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #208 on: January 15, 2006, 12:08:11 PM »
Djith and me ordered this mod, to put image name and category name in url.
After testing and debugging, we think it is ok now, and we are happy to share it with you.


This mod puts the names of the categories and the images in the url like this :
for image --->http://www.your-site.com/img-imagename-andnumber.htm
category --->http://www.your-site.com/cat-categoryname-andnumber.htm

you can see it working on http://www.edupics.com (1.7) and http://www.avatarcorner.com (1.7.1)
on these sites the "img" and "cat" in the url were changed to some keywords.
( see http://www.4homepages.de/forum/index.php?topic=6729.msg41243#msg41243 )


there is also the possibility to make url's with full path to image and categories : ( see //comment in mod )
for image --->http://www.your-site.com/img-full path to image.htm
category --->http://www.your-site.com/cat-full path of category.htm
This was not tested on our sites.


Don't forget to backup your files before editing !

files to be edited :
.htaccess
includes/sessions.php

Code: [Select]
 
=================================================
1. at the end of .htaccess, add following code :
=================================================
#Mod_bmollet : category name in URL
RewriteRule ^cat-(.*)-([0-9]+).htm categories.php?cat_id=$2&%{QUERY_STRING}
#Mod_bmollet : Image name in URL
RewriteRule ^img-(.*)-([0-9]+).htm details.php?image_id=$2&%{QUERY_STRING}

#Mod_bmollet : This is to make search function work  ( redirect links from search results )
RewriteRule ^img([0-9]+).search.htm details.php?image_id=$1&%{QUERY_STRING}

=======================================================================

=========================================
2. add this code to include/sessions.php
=========================================
//Mod_bmollet
/**
 * Get the category url
 * @param int $cat_id The id of the category
 * @param string $cat_url The current status of the URL
 */
function get_category_url($cat_id,$cat_url = '')
{
global $site_db;
$sql = "SELECT cat_name,cat_parent_id FROM ".CATEGORIES_TABLE." WHERE cat_id = '".$cat_id."'";
$result = $site_db->query($sql);
$row = $site_db->fetch_array($result);
$row['cat_name'] = strtr($row['cat_name'], "éèêàëâúóíáABCDEFGHIJKLMNOPQRSTUVWXYZ","eeeaeauoiaabcdefghijklmnopqrstuvwxyz");
$cat_url  = '-'.str_replace('+','-',urlencode($row['cat_name'])).'-'.$cat_id.$cat_url;
// if you want full path of category in url, put next line in comment
return $cat_url;
if( $row['cat_parent_id'] != 0)
{
return get_category_url($row['cat_parent_id'],$cat_url);
}
else
{
return $cat_url;
}
}
//Mod_bmollet
/**
 * Get the image url
 * @param int $image_id The id of the image
 */
function get_image_url($image_id)
{
global $site_db;
$sql = "SELECT cat_id,image_name FROM ".IMAGES_TABLE." WHERE image_id = '".$image_id."'";
$result = $site_db->query($sql);
$row = $site_db->fetch_array($result);
$row['image_name'] = strtr($row['image_name'], "éèêàëâúóíáABCDEFGHIJKLMNOPQRSTUVWXYZ","eeeaeauoiaabcdefghijklmnopqrstuvwxyz");
// if you want comlpete path to image in url, remove comment from following line
//return get_category_url($row['cat_id']).'-'.str_replace('+','-',urlencode($row['image_name'])).'-'.$image_id;
return '-'.str_replace('+','-',urlencode($row['image_name'])).'-'.$image_id;
}
========================================================================

========================================================================
3. In include/sessions.php replace function url(...) by following code.
========================================================================
/* ORIGINAL CODE
  function url($url, $amp = "&") {
    global $l;
    $dummy_array = explode("#", $url);
    $url = $dummy_array[0];

    if ($this->mode == "get" && !preg_match("/".SESSION_NAME."=/i", $url)) {
      $url .= preg_match("/\?/", $url) ? "$amp" : "?";
      $url .= SESSION_NAME."=".$this->session_id;
    }

    if (!empty($l)) {
      $url .= preg_match("/\?/", $url) ? "$amp" : "?";
      $url .= "l=".$l;
    }

    $url .= (isset($dummy_array[1])) ? "#".$dummy_array[1] : "";
    return $url;
  }
*/
  function url($url, $amp = "&") {
    global $l, $user_info;
    $dummy_array = explode("#", $url);
    $url = $dummy_array[0];
    $url = str_replace('&', '&', $url);
    if (!defined('IN_CP')) {
      if (strstr($url, 'index.php')) {
        $url = str_replace('index.php', '', $url);
      }
      elseif (strstr($url, 'search.php')) {
        if (strstr($url, 'page=')) {
          preg_match('#page=([0-9]+)&?#', $url, $matches);
          if (isset($matches[1])) {
            $split = explode('?', $url);
            $url = $split[0];
            $query = @$split[1];
            $url   = str_replace('search.php', 'search.'.$matches[1].'.htm', $url);
            $query = str_replace('page='.$matches[1].'&', '', $query);
            $query = str_replace('&page='.$matches[1], '', $query);
            $query = str_replace('page='.$matches[1], '', $query);
            if (!empty($query)) {
              $url .= '?' . $query;
            }
          }
        }
        else {
          $url = str_replace('search.php', 'search.htm', $url);
        }
      }
      elseif (strstr($url, 'lightbox.php')) {
        if (strstr($url, 'page=')) {
          preg_match('#page=([0-9]+)&?#', $url, $matches);
          if (isset($matches[1])) {
            $split = explode('?', $url);
            $url = $split[0];
            $query = @$split[1];
            $url   = str_replace('lightbox.php', 'lightbox.'.$matches[1].'.htm', $url);
            $query = str_replace('page='.$matches[1].'&', '', $query);
            $query = str_replace('&page='.$matches[1], '', $query);
            $query = str_replace('page='.$matches[1], '', $query);
            if (!empty($query)) {
                $url .= '?' . $query;
            }
          }
        }
        else {
          $url = str_replace('lightbox.php', 'lightbox.htm', $url);
        }
      }
      elseif (strstr($url, 'categories.php')) {
        if (strstr($url, 'cat_id=') && strstr($url, 'page=')) {
          preg_match('#cat_id=([0-9]+)&?#', $url, $matches1);
          preg_match('#page=([0-9]+)&?#', $url, $matches2);
          if (isset($matches1[1]) && isset($matches2[1])) {
            $split = explode('?', $url);
            $url = $split[0];
            $query = @$split[1];
            $url   = str_replace('categories.php', 'cat'.$matches1[1].'.'.$matches2[1].'.htm', $url);
            $query = str_replace('cat_id='.$matches1[1].'&', '', $query);
            $query = str_replace('&cat_id='.$matches1[1], '', $query);
            $query = str_replace('cat_id='.$matches1[1], '', $query);
            $query = str_replace('page='.$matches2[1].'&', '', $query);
            $query = str_replace('&page='.$matches2[1], '', $query);
            $query = str_replace('page='.$matches2[1], '', $query);
            if (!empty($query)) {
              $url .= '?' . $query;
            }
          }
        }
        elseif (strstr($url, 'cat_id=')) {
          preg_match('#cat_id=([0-9]+)&?#', $url, $matches);
          if (isset($matches[1])) {
            $split = explode('?', $url);
            $url = $split[0];
            $query = @$split[1];
            $cat_url = get_category_url($matches[1]);
            $url   = str_replace('categories.php', 'cat'.$cat_url.'.htm', $url);
            $query = str_replace('cat_id='.$matches[1].'&', '', $query);
            $query = str_replace('&cat_id='.$matches[1], '', $query);
            $query = str_replace('cat_id='.$matches[1], '', $query);
            if (!empty($query)) {
              $url .= '?' . $query;
            }
          }
        }
        else {
          $url = str_replace('categories.php', 'cat.htm', $url);
        }
      }
      elseif (strstr($url, 'details.php?image_id=')) {
        if (strstr($url, 'image_id=') && strstr($url, 'mode=')) {
          preg_match('#image_id=([0-9]+)&?#', $url, $matches1);
          preg_match('#mode=([a-zA-Z0-9]+)&?#', $url, $matches2);
          if (isset($matches1[1]) && isset($matches2[1])) {
            $split = explode('?', $url);
            $url = $split[0];
            $query = @$split[1];
            $url   = str_replace('details.php', 'img'.$matches1[1].'.'.$matches2[1].'.htm', $url);
            $query = str_replace('image_id='.$matches1[1].'&', '', $query);
            $query = str_replace('&image_id='.$matches1[1], '', $query);
            $query = str_replace('image_id='.$matches1[1], '', $query);
            $query = str_replace('mode='.$matches2[1].'&', '', $query);
            $query = str_replace('&mode='.$matches2[1], '', $query);
            $query = str_replace('mode='.$matches2[1], '', $query);
            if (!empty($query)) {
              $url .= '?' . $query;
            }
          }
        }
        else {
          preg_match('#image_id=([0-9]+)&?#', $url, $matches);
          if (isset($matches[1])) {
            $split = explode('?', $url);
            $url = $split[0];
            $query = @$split[1];
            $url   = str_replace('details.php', 'img'.get_image_url($matches[1]).'.htm', $url);
            $query = str_replace('image_id='.$matches[1].'&', '', $query);
            $query = str_replace('&image_id='.$matches[1], '', $query);
            $query = str_replace('image_id='.$matches[1], '', $query);
            if (!empty($query)) {
              $url .= '?' . $query;
            }
          }
        }
      }
      elseif (strstr($url, 'postcards.php?image_id=')) {
        preg_match('#image_id=([0-9]+)&?#', $url, $matches);
        if (isset($matches[1])) {
          $split = explode('?', $url);
          $url = $split[0];
          $query = @$split[1];
          $url   = str_replace('postcards.php', 'postcard.img'.$matches[1].'.htm', $url);
          $query = str_replace('image_id='.$matches[1].'&', '', $query);
          $query = str_replace('&image_id='.$matches[1], '', $query);
          $query = str_replace('image_id='.$matches[1], '', $query);
          if (!empty($query)) {
            $url .= '?' . $query;
          }
        }
      }
    }
    if ($this->mode == "get" && strstr($url, $this->session_id)) {
      $url .= strpos($url, '?') !== false ? '&' : '?';
      $url .= SESSION_NAME."=".$this->session_id;
    }
    if (!empty($l)) {
      $url .= strpos($url, '?') ? '&' : '?';
      $url .= "l=".$l;
    }
    $url = str_replace('&', $amp, $url);
    $url .= isset($dummy_array[1]) ? "#".$dummy_array[1] : "";
    return $url;
  }
========================================================================


========================================================================
4. In include/sessions.php following functions are useful for URL's like
   yoursite.com/maincategory/subcategory/imagename.htm
   
   This is not necessairy if you want url's (like we used on our sites) like this :
   for image --->http://www.your-site.com/img-imagename-andnumber.htm
   category --->http://www.your-site.com/cat-categoryname-andnumber.htm
========================================================================
//Mod_bmollet
/**
 * Get the category id
 * @param array $path An array with the path of the category
 * @param int $parent_id The parent id of the first item in the $path
 */
function get_category_id($path,$parent_id = 0)
{
$cat_name = array_shift($path);
global $site_db;
$sql = "SELECT cat_id FROM ".CATEGORIES_TABLE." WHERE cat_parent_id = $parent_id AND cat_name = '".mysql_real_escape_string($cat_name)."'";
$result = $site_db->query($sql);
$row = $site_db->fetch_array($result);
if( count($path) != 0)
{
return get_category_id($path,$row['cat_id']);
}
else
{
return $row['cat_id'];
}
}
//Mod_bmollet
/**
 * Get the image id
 * @param array $path An array with the path of the image
 */
function get_image_id($path)
{
global $site_db;
$image_name = array_pop($path);
$cat_id = get_category_id($path);
$sql = "SELECT image_id FROM ".IMAGES_TABLE." WHERE image_name = '".mysql_real_escape_string($image_name)."' AND cat_id = $cat_id";
$result = $site_db->query($sql);
$row = $site_db->fetch_array($result);
return $row['image_id'];
}
========================================================================


Offline djith

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #209 on: January 16, 2006, 09:14:50 PM »
Can't believe that nobody noticed the mod here above!!  :D
Well... try it out guys !!