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

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

0 Members and 1 Guest are viewing this topic.

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[Mod] Search Engine Friendly URLs aka Short URLs
« on: March 14, 2005, 04:17:30 PM »
Quote
There is some speculation as to whether or not a search engine will crawl pages that have a URL with a query string:
Code: [Select]
categories.php?cat_id=12&page=2The webmaster documentation for some search engines suggests their crawlers will not crawl pages with these types of URLs as they may represent and INFINITE URL space.  Frankly, Google has ALWAYS crawled all of my web pages with these URLs with no problems.  My opinion is that it is the session id in a query string that may influence the crawler.

The following was recovered from search engine cache and restored by me. I did not write this mod

This mod will convert your 4images URLs into shorter URLs and remove the query string.  This mod requires an Apache compatible web server.

Step 1
Open /includes/sessions.php
Find:
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;
  }
Replace with:
Code: [Select]
/* 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];
            $url   = str_replace('categories.php', 'cat'.$matches[1].'.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'.$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;
  }

Step 2
Create a new file named .htaccess (note the leading period that starts the file name) or edit your existing .htaccess file in the root level of your 4images installation.  Place the following lines inside that file:
Code: [Select]
# Begin search engine friendly links code
RewriteEngine On
#RewriteBase /
RewriteRule ^lightbox\.htm$ lightbox.php?%{QUERY_STRING}
RewriteRule ^lightbox\.([0-9]+)\.htm$ lightbox.php?page=$1&%{QUERY_STRING}

RewriteRule ^search\.htm$ search.php?%{QUERY_STRING}
RewriteRule ^search\.([0-9]+)\.htm$ search.php?page=$1&%{QUERY_STRING}

RewriteRule ^cat\.htm$ categories.php?%{QUERY_STRING}
RewriteRule ^cat([0-9]+)\.([0-9]+)\.htm$ categories.php?cat_id=$1&page=$2&%{QUERY_STRING}
RewriteRule ^cat([0-9]+)\.htm$ categories.php?cat_id=$1&%{QUERY_STRING}

RewriteRule ^img([0-9]+)\.htm$ details.php?image_id=$1&%{QUERY_STRING}
RewriteRule ^img([0-9]+)\.([a-zA-Z0-9]+)\.htm$ details.php?image_id=$1&mode=$2&%{QUERY_STRING}

RewriteRule ^postcard([a-zA-Z0-9]+)\.htm$ postcards.php?postcard_id=$1&%{QUERY_STRING}
RewriteRule ^postcard\.img([0-9]+)\.htm$ postcards.php?image_id=$1&%{QUERY_STRING}

# End search engine friendly links code

If for some reason it doesnt work for u, make sure that mod_rewrite is installed on your server and that the vdomain/dir of yours has permissions to use it (contact your hoster if u are not sure).
If it still doesnt work, try to uncomment:
Code: [Select]
#RewriteBase /
and replace / with the path to 4image root dir in your address bar.
(for example if your gallery address is: www.example.com/pix/
then u should add:
Code: [Select]
RewriteBase /pix/
Revision History:
  • Restored sessions.php mod code from search engine cached page
« Last Edit: February 05, 2006, 09:06:11 PM by V@no »

Spadver

  • Guest
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #1 on: March 14, 2005, 08:12:05 PM »
Thank you!

But is it all?

As far as I remember, there must be some additional code in 4images.

May be for getting
Quote
QUERY_STRING
?


Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile

Offline marod0er

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #3 on: March 15, 2005, 05:43:26 PM »
No, there's more.

I remember changing something sessions.php
Greetz: Lasse

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #4 on: March 15, 2005, 06:37:59 PM »
Yeah, I came across it while digging through search engine cached pages.  I've updated the original post

Offline G4

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #5 on: March 15, 2005, 09:14:50 PM »
a situpid question :?

i made all the changes, but how can i see that it is working?

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 #6 on: March 16, 2005, 12:27:42 AM »
a situpid question :?

i made all the changes, but how can i see that it is working?
just visit your site and see what kind of URLs it shows
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 marod0er

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #7 on: March 16, 2005, 08:07:23 PM »
Thanks for making the change chris, appreciate it... This is for version 1.7.1 right?
Greetz: Lasse

Offline redhead_tn

  • Pre-Newbie
  • Posts: 6
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #8 on: March 16, 2005, 09:41:19 PM »
worked "right out the box" ... thanks

using with 4images 1.7

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 #9 on: March 16, 2005, 11:38:03 PM »
This is for version 1.7.1 right?
originaly it was made before v1.7.1 even planned to be released ;)
but it should work with v1.7.1 as well.
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 G4

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #10 on: March 16, 2005, 11:55:15 PM »

Offline marod0er

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #11 on: March 16, 2005, 11:59:56 PM »
if the links look like this
http://www.website.com/galerie/details.php?image_id=48&sessionid=0e5c89cf1ac5434bb45223b0e62dc28c
it doesn´t work

and if ithey look like this
http://www.website.com/details.php?image_id=8
it works.

is this right?

Not quite. Those 2 URLs you have there are the same. The one on top just has a sessionid.

It should look like this:

http://www.website.com/img8.htm (assuming you havn't made any changes to your .htaccess file)
Greetz: Lasse

Offline abdoh2010

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Racing 4 Education
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #12 on: March 21, 2005, 08:45:07 PM »
could you pleass update it to 1.7.1 ?

it's dont work with it

Offline abdoh2010

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
    • Racing 4 Education
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #13 on: March 21, 2005, 09:02:18 PM »
i fix it

it only need '}' at the end of the code

Offline marod0er

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #14 on: March 24, 2005, 06:31:22 PM »
Can anyone make it, so it's able to convert those "template" pages to html files as well?

I mean:

Let's say you have this MOD running perfectly, but you also has extra pages that's not originally "in the software" like, if you have a page named "Privacy Policy" or whatever, you can get 4images to make a page, that runs on the index.php. It will look something like this: http://www.site.com/index.php?template=privacy

Now, what I want, is to get it to look like: http://www.site.com/privacy.html

Is this possible? I bet it is... Vano, a little help? ;)
Greetz: Lasse