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

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

0 Members and 2 Guests are viewing this topic.

Offline Maweryk

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #120 on: September 27, 2005, 02:03:36 AM »
I try it out, but without success.  :cry:

@v@no: Can you help us?  :roll:

Thanks!

Markus


Great idea!
How can we do that?

My idea:

Category: mysite.com/ID-category_name.htm
Details: mysite.com/ID-category_name-imgID.htm

Thanks for helping!

Cheers,

Markus



Hello,

as my post may be overread, and i think it is important for us all, here again:

Hello,

I know it has been asked seveal times in this topic before, and also it has been given an answer, but I want to give a suggestion for this...

Question is: Can I change the URL: mysite.com/img123.htm to mysite.com/image_name.htm ?

The answer was: NO, because when 2 images have same name, it won´t work, the 4images is based on unique ID-Numbers.

Ok, here comes my suggestion:

Could we generate URLs like this instead, so we have still the ID, but we´re using the image or cat name in the URL, which helps a lot in SEO :

mysite.com/image_name-ID.htm or
mysite.com/image_name/ID.htm

Regards,
Daniel


Offline djith

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #121 on: September 30, 2005, 08:39:28 AM »
This is over the line, my webhosting service doesn't allow me to use search engine friendly urls !!!!
i asked them to make an .htaccess file for me and this is the answer i got...

Reason enough to brake up with them and transfer my site to another hosting company!!!

Dear Valued Customer,

Thank you for writing us, we would like to inform you that we dont allow
friendly urls this is not supported other .htaccess that are not supported are
as follows:

   AddCharSet
   AddEncoding
   AddLanguage
   AddType
   BrowserMatch
   BrowserMatchNoCase
   CookieTracking
   DefaultLanguage
   DefaultType
   ErrorDocument
   ErrorHeader
   Header
   LanguagePriority
   Options
   PassEnv
   Redirect
   RedirectMatch
   RedirectPermanent
   RedirectTemporary
   SetEnv
   SetEnvIf
   SetEnvIfNoCase
   UnsetEnv

If you want to create .htaccess file you can google for directions and how to
procedures but make sure that the kind of file your going to create is not on
the list.

Thank you for contacting our technical support. If you have any further
questions, please reply to this email leaving all text intact, and be sure to
give us a detailed description of how we can further assist you.
 
Best regards,

Ken
Globat Support
support@globat.com

Web Hosting Made Easy®
www.Globat.com

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 #122 on: September 30, 2005, 02:55:50 PM »
That is very common between host companies. mod_rewrite is a quet "havy" on server resources...cant really blame them for not supporting 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 Flo2005

  • Full Member
  • ***
  • Posts: 237
  • Copy & Paste Profi :)
    • View Profile
    • snuup.de! - Bilder - Sounds - Videos - fun4FREE!
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #123 on: October 02, 2005, 06:55:42 PM »
Hi!

1. I enabled mod_rewrite on my localhost
2. I changed my sessions.php
3. I edited my .htaccess
4. I get this error-message

Quote
Parse error: parse error, expecting `T_FUNCTION' in -> path to my apache-root-folder \lite\includes\sessions.php on line 536

Quote
Line 536 of my sessions.php: define('COOKIE_NAME', '4images_');

Ps: In my .htacces I have allready done - > RewriteBase /lite/

THX

by Flo

Project offline

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 #124 on: October 03, 2005, 05:24:35 AM »
You've made a misstake in sessions.php
Restore backups and try again.
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 Flo2005

  • Full Member
  • ***
  • Posts: 237
  • Copy & Paste Profi :)
    • View Profile
    • snuup.de! - Bilder - Sounds - Videos - fun4FREE!
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #125 on: October 03, 2005, 08:38:09 AM »
I restored my sessions.php and add the code and became the same error like before  :?

I think I have changed something for longer time http://www.vierstra.com/forum/forum-subject.php/t/987 this must have to do with my problem  :!:  :?: :!: :!:

But, I have comment out this changes...

Project offline

Offline lapinkulta

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Avatar Essentials
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #126 on: October 06, 2005, 08:54:18 PM »
Hi V@no!

I have my site in two languages (more to come :-)) and i am using your code from this thread.

How would i need to change it if i would like to have:

./category1_en.htm instead of ./category1.htm?l=english

???

I'm sure you can help me here.

lapinkulta
Two hours of try and error can save ten minutes of manual reading.

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 #127 on: October 07, 2005, 01:13:03 AM »
lets try this:

Replace the code from the original post in sessions.php with this version:
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);
    $ext = "";
/*
  comment out the following lines if you dont want append _<lang> to the filenames. If you do so, you'll need uncomment lines at the end of this function.
*/
    if (!empty($l)) {
      $ext = "_".$l;
    }
/*end commented block*/
    $ext .= ".htm";
    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].$ext, $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'.$ext, $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].$ext, $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'.$ext, $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].$ext, $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].$ext, $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'.$ext, $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].$ext, $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].$ext, $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].$ext, $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;
    }
/*
  uncomment the following lines if you want append ?l=<lang>
*/
/*
    if (!empty($l)) {
      $url .= strpos($url, '?') ? '&' : '?';
      $url .= "l=".$l;
    }
*/
    $url = str_replace('&', $amp, $url);
    $url .= isset($dummy_array[1]) ? "#".$dummy_array[1] : "";
    return $url;
  }


Then in .htaccess replace the code with the folowing:
Code: [Select]
# Begin search engine friendly links code
RewriteEngine On
#RewriteBase /
RewriteRule ^lightbox(\.([0-9]+))?(_([a-zA-Z]+))?\.htm$ lightbox.php?page=$2&l=$4&%{QUERY_STRING}

RewriteRule ^search(\.([0-9]+))?(_([a-zA-Z]+))?\.htm$ search.php?page=$2&l=$4&%{QUERY_STRING}

RewriteRule ^cat([0-9]+)?(\.([0-9]+))?(_([a-zA-Z]+))?\.htm$ categories.php?cat_id=$1&page=$3&l=$5&%{QUERY_STRING}

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

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

# End search engine friendly links code

Please note, I have not tested it myself and the language name appended to filenames will be the same as the name of your language folders, for example if you have two folders in your /lang/ dir english and deutsch then the filenames will like category1_english.htm or category1_deutsch.htm
If you want it to be shorter, then you'll need to rename your folders ;) (but then dont forget add l=<new name> to the ACP url, otherwise you wont be able get anywhere to update the settings.)
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 Maweryk

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #128 on: October 07, 2005, 05:37:44 AM »
Thanks, vano!!!
It is possible to add the name of the category?

Home/Test

category1_test_english.htm

Thanks!

Markus

Offline lapinkulta

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Avatar Essentials
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #129 on: October 07, 2005, 09:22:05 AM »
Hi Vano!

Thanks works great.

Only problem is, that links for the standard language are always generated without the appended language.
So cat1.htm instead of cat1_english.htm

Where could I change that so even for the standard language the string is appended (or the filename correctly written).

Thanks,
lapinkulta
Two hours of try and error can save ten minutes of manual reading.

Offline lapinkulta

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Avatar Essentials
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #130 on: October 07, 2005, 09:34:33 AM »
OK i have changed:

Code: [Select]
    if (!empty($l)) {
      $ext = "_".$l;
    }

to

Code: [Select]
    if (!empty($l)) {
      $ext = "_".$l;
    }
    if (empty($l)) {
      $ext = "_english";
    }

to have also "_english" appended for the standard language.

What does NOT work:


For the links to lightbox, search, register, member etc. the language (either standard or other, with or without that change above) is not appended...

Greetings,
lapinkulta
Two hours of try and error can save ten minutes of manual reading.

Offline lapinkulta

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Avatar Essentials
Re: [Mod] Search Engine Friendly URLs aka Short URLs
« Reply #131 on: October 14, 2005, 06:10:34 PM »
*bump*
Two hours of try and error can save ten minutes of manual reading.

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 #132 on: October 14, 2005, 11:17:59 PM »
Only problem is, that links for the standard language are always generated without the appended language.
So cat1.htm instead of cat1_english.htm

Where could I change that so even for the standard language the string is appended (or the filename correctly written).
In global.php find:
Code: [Select]
$l = null;
Replace it with:
Code: [Select]
$l = $config['language_dir_default'];
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 #133 on: October 15, 2005, 11:27:28 AM »
Hi @all,

its some months ago, that i have been here on this forum. my webgallery works fine now, thanks to all of you (especially jan and v@no).
But i got a new serious problem. i´ve installes mod rewrite and so i got duplicate content in google, now. the biggest problem seems to be the search.htm.

for example:
www.domain.de/search.htm?search_user=G4
www.domain.de/search.php?search_user=G4

or

http://www.domain.de/img1562.search.htm
http://www.domain.de/img1562.htm


i found this in this thread, does this solve my problem?

or another alternative replace in search.php:
Code:
    show_image($image_row, "search");
with:
Code:
    show_image($image_row);
(I think this is better Wink)

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 #134 on: October 15, 2005, 01:59:00 PM »
what EXACTLY is the problem?
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)