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

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

0 Members and 1 Guest 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 #345 on: September 02, 2006, 02:36:40 AM »
what is the difference in the seo and normal urls for the second page?
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 Brainwrek

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #346 on: September 02, 2006, 05:06:42 AM »
This should be easy, but I haven't found a solution yet...

How to use .htaccess to rewrite the Keywords links from this:
Code: [Select]
<a href=" http://www.site.com/photos/search.htm?search_keywords=dogs_cats">DOGS & CATS</a>
To this:
Code: [Select]
<a href=" http://www.site.com/photos/keywords/dogs_cats">DOGS & CATS</a>
I would love to have this!!!

Offline Bugfixed

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Lavinya
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #347 on: September 09, 2006, 05:04:30 PM »
hello all.

I have big problem. my problem is this system is showing doesnt lacking pages.
for example: there is no addresses like http://www.lavinya. net/galeri/img19933.htm :(
but it is showing . redirect to main page (with 302 status code).

file not 302, it must be 404 status code. this is spam I think.  8O

please help me  :?
<?php echo 'Hello, World!'; ?>

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 #348 on: September 09, 2006, 07:07:36 PM »
I didnt understand...how is that related to this mod?
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 xec

  • Pre-Newbie
  • Posts: 8
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #349 on: September 17, 2006, 08:25:58 AM »
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 = "&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 = "&amp;") {
    global $l, $user_info;
    $dummy_array = explode("#", $url);
    $url = $dummy_array[0];
    $url = str_replace('&amp;', '&', $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'];
}
========================================================================


Hello,

Has someone gotten this to work with 1.7.2 ? Thank you.

Offline vBFreak

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Gerrits Forum
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #350 on: September 17, 2006, 08:37:12 AM »
Heh, that's exactly what I was looking for, thanks a lot :)

How can I replace member urls to http://www.domain.de/members/username ? (Also special chars like . or , or umlauts should be removed and spaces should be re-written to -)

Would also be good to be able to rewrite http://www.domain.de/cat56.html?page=2 to http://www.domain.de/cat56_2.htm

As far as I can see google still craws on dynamic urls, will they stop using those old ones after a while and will add the new html ones then instead?
« Last Edit: September 17, 2006, 09:49:24 AM by vBFreak »

Offline xec

  • Pre-Newbie
  • Posts: 8
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #351 on: September 18, 2006, 02:27:12 AM »
Heh, that's exactly what I was looking for, thanks a lot :)

How can I replace member urls to http://www.domain.de/members/username ? (Also special chars like . or , or umlauts should be removed and spaces should be re-written to -)

Would also be good to be able to rewrite http://www.domain.de/cat56.html?page=2 to http://www.domain.de/cat56_2.htm

As far as I can see google still craws on dynamic urls, will they stop using those old ones after a while and will add the new html ones then instead?
So you're saying you got for image --->http://www.your-site.com/img-imagename-andnumber.htm
category --->http://www.your-site.com/cat-categoryname-andnumber.htm working on your 1.7.3 4images site?

Offline vBFreak

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Gerrits Forum
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #352 on: September 18, 2006, 02:20:41 PM »
No, I'm using 4images 1.7.2 with the security fixes because I'm using a special integration to my vBulletin Forums, the sessions.php from 1.7.3 differs from the one of 1.7.2, thus I'm unable to update my 4images until a new, up to date Version of my integration mod is released.

I'm using the version from the first post in this thread, I didn't get the one from page 14 to work, I think that was the one you mentioned.

Offline xec

  • Pre-Newbie
  • Posts: 8
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #353 on: September 19, 2006, 06:18:19 PM »
No, I'm using 4images 1.7.2 with the security fixes because I'm using a special integration to my vBulletin Forums, the sessions.php from 1.7.3 differs from the one of 1.7.2, thus I'm unable to update my 4images until a new, up to date Version of my integration mod is released.

I'm using the version from the first post in this thread, I didn't get the one from page 14 to work, I think that was the one you mentioned.
Sorry, I meant to ask if you got the page 14 one to work with 1.7.2 but I guess you answered for me. So what mod is it that you're using? The user integration mod?

Offline live@ct

  • Sr. Member
  • ****
  • Posts: 348
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #354 on: September 20, 2006, 10:44:30 AM »
I install the second MOD of this (Page 14) but I get this error:

Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/content/html/includes/sessions.php on line 626

And returning to my last problem, (I added an alias domian to my actual site and the original MOD didnt work) when I acces aliasdomian.com/cat3.html it showme a ERROR 404 file not found, but if I acces aliasdomain.com/categories.php?cat_id=3 it works fine

thanks for your help
Existen 10 tipos de personas, los que entienden el codigo binario y los que no.

Offline saadahmed007

  • Pre-Newbie
  • Posts: 3
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #355 on: September 20, 2006, 06:18:48 PM »
Hi Vano,
I am getting 404 error on the site
http://www.t-mobile-t.com/
on images if you look into it
Will really apperciate your guidence :)
Thanks and Regards,
Saad

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 #356 on: September 21, 2006, 01:09:14 AM »
404 error is not usefull untill you look in the logs ;)
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 adrianus

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #357 on: September 21, 2006, 07:28:37 PM »
hi to all

So the mod at 14th page still doesn't work with 1.7.3... is it right?

Are there any SEF solutions for 1.7.3 (i don't like the 1th page one).

thanks to all
AD

Offline live@ct

  • Sr. Member
  • ****
  • Posts: 348
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #358 on: September 27, 2006, 09:57:25 AM »
Hi

I add the next line to my httacces

RewriteRule ^([a-zA-Z0-9_\-]+)\.html$ index.php?template=$1&%{QUERY_STRING}

now I cant retrive a simple html out of the script of 4images

someone can help me with this error?!
Existen 10 tipos de personas, los que entienden el codigo binario y los que no.

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 #359 on: September 28, 2006, 03:16:22 AM »
1) page 14 - might be different for everyone, it depence on personal settings on this forum so, please post a url to the reply you are talking about instead.
2) you've made a misstake when modifyed sessions.php perhaps missed { or }
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)