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

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

0 Members and 4 Guests are viewing this topic.

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 #255 on: April 05, 2006, 08:49:47 AM »
I've updated my previous post ;) should work now
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 himu

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
    • Point Of View
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #256 on: April 05, 2006, 09:43:26 AM »
Great!!!! working fine... Thanks a lot... v@no
 8)
I've updated my previous post ;) should work now

Offline marod0er

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #257 on: April 07, 2006, 04:36:37 PM »
Hey people,

I've noticed a lot of you have asked a way to completely remove sessionid's, as google DOES NOT like it.

Just add this somewhere in your .htaccess:

Code: [Select]
php_value session.use_cookies 1
php_value session.use_only_cookies 1
php_value session.use_trans_sid 0

Just add it at the very end of your .htaccess (for instance), and session id's are gone for good :D
Greetz: Lasse

Offline Eagle Eye

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #258 on: April 07, 2006, 04:42:50 PM »
Hey people,

I've noticed a lot of you have asked a way to completely remove sessionid's, as google DOES NOT like it.

Just add this somewhere in your .htaccess:

Code: [Select]
php_value session.use_cookies 1
php_value session.use_only_cookies 1
php_value session.use_trans_sid 0

Just add it at the very end of your .htaccess (for instance), and session id's are gone for good :D

getting internal server error 500  :(

Offline marod0er

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #259 on: April 07, 2006, 04:48:33 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'];
}
========================================================================

Cool MOD, but frankly it doesn't make sense.
What exactly are we supposed to do in order to get URLs like:

http://www.site.com/category/imagename.html ?
Greetz: Lasse

Offline marod0er

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #260 on: April 07, 2006, 04:49:56 PM »
Hey people,

I've noticed a lot of you have asked a way to completely remove sessionid's, as google DOES NOT like it.

Just add this somewhere in your .htaccess:

Code: [Select]
php_value session.use_cookies 1
php_value session.use_only_cookies 1
php_value session.use_trans_sid 0

Just add it at the very end of your .htaccess (for instance), and session id's are gone for good :D

getting internal server error 500  :(
Can you show your htaccess file here (or PM it to me if you don't want it out in public)
Greetz: Lasse

Offline djith

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #261 on: April 07, 2006, 10:51:57 PM »
i found out that google read my entire website two times recently..... thought that it will be okay now ---session id's in cache----- but no sir-----still session id's------ i can see in cache of google that it read my site few days ago......


realy...... my friend mike has no session id's anymore in google...... vanished...... he has version 1.7
i think to downgrade my site to 1.7 ---seems to work whit 1.7

Offline tirakle

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #262 on: April 10, 2006, 06:22:23 PM »
Hi there,

I installed this mod and it is working almost perfectly. But I have 2 problems.

If I enter my site for the first time the url is changed e.g. into:

http://www.amazing-gifs.de/gifs/cat142.htm?sessionid=a83f0fa42dfde9479d7bd56e8a4789ee

if I enter the site for the secornd time the url´s name ist only:

http://www.amazing-gifs.de/gifs/cat142.htm


So that´s how I want it to be ( http://www.amazing-gifs.de/gifs/cat142.htm ) .

Why is the sessionid shown if I enter for the first time ?
What do I have to change so that all the URL looks like the second ??  ( I´m using version 1.7.2 )

After changing the files my the Control Center is not working right. Does anybody have this problem too ?

Can anybody plaease help ?


Offline djith

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #263 on: April 10, 2006, 10:17:03 PM »
i'm using 1.7.1 and has the same problem, i'm looking for a solution wich my previous post on this topic could be a solution i think.

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 #264 on: April 11, 2006, 02:48:14 AM »
Hi there,

I installed this mod and it is working almost perfectly. But I have 2 problems.

If I enter my site for the first time the url is changed e.g. into:

http://www.amazing-gifs.de/gifs/cat142.htm?sessionid=a83f0fa42dfde9479d7bd56e8a4789ee

if I enter the site for the secornd time the urlґs name ist only:

http://www.amazing-gifs.de/gifs/cat142.htm


So thatґs how I want it to be ( http://www.amazing-gifs.de/gifs/cat142.htm ) .

Why is the sessionid shown if I enter for the first time ?
What do I have to change so that all the URL looks like the second ?? ( Iґm using version 1.7.2 )

After changing the files my the Control Center is not working right. Does anybody have this problem too ?

Can anybody plaease help ?


sessionid is required for 4images, it only appiers when no cookies were set (first visit) or when they are disabled. If you want to disable sessionid in the url, you will only slow down your gallery and privent visitors with blocked cookies use your site with full features. please read the reply, we've discuss it here already.

@djith:
you did something wrong, I just followed my own instructions and it worked just fine on v1.7, 1.7.1 and v1.7.2 (the latter had different line to search for, though)
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 tirakle

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #265 on: April 11, 2006, 06:56:17 PM »
@ V@no

yes I know about the sessions. But I was just wondering why the session is shown in the url for one time. If I visit another site that uses 4images the session id does not appear.

since I changed the sessions.php file my control center does not work right. I can see only:

Warning: Cannot modify header information - headers already sent by (output started at /home/www/kunden/amazing-gifs.de/gifs/includes/sessions.php:604) in /home/www/kunden/amazing-gifs.de/gifs/admin/admin_functions.php on line 168

Warning: Cannot modify header information - headers already sent by (output started at /home/www/kunden/amazing-gifs.de/gifs/includes/sessions.php:604) in /home/www/kunden/amazing-gifs.de/gifs/admin/admin_functions.php on line 169

Warning: Cannot modify header information - headers already sent by (output started at /home/www/kunden/amazing-gifs.de/gifs/includes/sessions.php:604) in /home/www/kunden/amazing-gifs.de/gifs/admin/admin_functions.php on line 170

Warning: Cannot modify header information - headers already sent by (output started at /home/www/kunden/amazing-gifs.de/gifs/includes/sessions.php:604) in /home/www/kunden/amazing-gifs.de/gifs/admin/admin_functions.php on line 171

Warning: Cannot modify header information - headers already sent by (output started at /home/www/kunden/amazing-gifs.de/gifs/includes/sessions.php:604) in /home/www/kunden/amazing-gifs.de/gifs/admin/admin_functions.php on line 172


Do you know what went wrong or can anybody help ??

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 #266 on: April 12, 2006, 01:59:55 AM »
yes, and its covered in the FAQ, most probably you left a space or a newline after ?>

P.S. what other site did you visit that did not show sessionid? unless that site used the sessionid removal code, its not possible UNLESS, you've visited it once before and the sessionid was left in your cookies.
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 commandos

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Quran Recitation
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #267 on: April 13, 2006, 07:18:47 AM »
Hey people,

I've noticed a lot of you have asked a way to completely remove sessionid's, as google DOES NOT like it.

Just add this somewhere in your .htaccess:

Code: [Select]
php_value session.use_cookies 1
php_value session.use_only_cookies 1
php_value session.use_trans_sid 0

Just add it at the very end of your .htaccess (for instance), and session id's are gone for good :D

Any disavantage of this version ? because it work for me

Offline commandos

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Quran Recitation
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #268 on: April 13, 2006, 01:17:16 PM »
it was working yesterday no more sessionsid's ..... woke up today to see that it was giving 502 error ...  :x

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #269 on: April 17, 2006, 04:45:23 AM »
I love this mod!!! google loves it too :):)