[SEO] MakeURLSafe and the '/' character

For Articles relating to more than one ISC version
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

[SEO] MakeURLSafe and the '/' character

Post by Martin »

Just a small note that I've come across while sorting out my spidering system.

In /lib/general.php there are two functions that encode certain characters into "safe" alternatives and invariably they are used when translating a CMS or product page title into a SEO friendly url.

Unfortunately for reasons best known to Interspire, they've used the encoding {47} for the '/' character which in some instances breaks spidering or searching and results in an error.

The fix for this is as follows:

Open: /lib/general.php

Find:

Code: Select all

	function MakeURLSafe($val)
	{
		$val = str_replace("-", "%2d", $val);
		$val = str_replace("+", "%2b", $val);
		$val = str_replace("+", "%2b", $val);
		$val = str_replace("/", "{47}", $val);
		$val = urlencode($val);
		$val = str_replace("+", "-", $val);
		return $val;
	}

	/**
	 * Convert an already search engine friendly based string back to the normal text equivalent.
	 *
	 * @param string The search engine friendly version of the string.
	 * @return string The normal textual version of the string.
	 */
	function MakeURLNormal($val)
	{
		$val = str_replace("-", " ", $val);
		$val = urldecode($val);
		$val = str_replace("{47}", "/", $val);
		$val = str_replace("%2d", "-", $val);
		$val = str_replace("%2b", "+", $val);
		return $val;
	}

Replace with:

Code: Select all

	function MakeURLSafe($val)
	{
		$val = str_replace("-", "%2d", $val);
		$val = str_replace("+", "%2b", $val);
		$val = str_replace("+", "%2b", $val);
		$val = str_replace("/", "%2f", $val);
		$val = urlencode($val);
		$val = str_replace("+", "-", $val);
		return $val;
	}

	/**
	 * Convert an already search engine friendly based string back to the normal text equivalent.
	 *
	 * @param string The search engine friendly version of the string.
	 * @return string The normal textual version of the string.
	 */
	function MakeURLNormal($val)
	{
		$val = str_replace("-", " ", $val);
		$val = urldecode($val);
		$val = str_replace("{47}", "/", $val);
		$val = str_replace("%2f", "/", $val);
		$val = str_replace("%2e", "/", $val);
		$val = str_replace("%2d", "-", $val);
		$val = str_replace("%2b", "+", $val);
		return $val;
	}
Any existing products, categories, etc.. that have the '/' character in them will have their URL updated whenever you save any changes if you apply this mod so bear in mind the SEO implications for your site.

SamX
Posts: 14
Joined: Thu Jul 09, 2009 11:26 pm

Re: [SEO] MakeURLSafe and the '/' character

Post by SamX »

Thank you!!! to complete this hack for spanish users who wants to add characters like:

á, é, í, ó, ú and ñ

Code: Select all

   function MakeURLSafe($val)
   {
      $val = str_replace("-", "%2d", $val);
      $val = str_replace("+", "%2b", $val);
      $val = str_replace("+", "%2b", $val);
      $val = str_replace("/", "%2f", $val);
       /**        *Spanish Characters    - Start     */
          $val = str_replace("ñ", "n", $val);
          $val = str_replace("á", "a", $val);
          $val = str_replace("é", "e", $val);
          $val = str_replace("í", "i", $val);
          $val = str_replace("ó", "o", $val);
          $val = str_replace("ú", "u", $val);
       /**        *Spanish Characters    - End    */
      $val = urlencode($val);
      $val = str_replace("+", "-", $val);
      return $val;
   }

   /**
    * Convert an already search engine friendly based string back to the normal text equivalent.
    *
    * @param string The search engine friendly version of the string.
    * @return string The normal textual version of the string.
    */
   function MakeURLNormal($val)
   {
      $val = str_replace("-", " ", $val);
      $val = urldecode($val);
      $val = str_replace("{47}", "/", $val);
      $val = str_replace("%2f", "/", $val);
      $val = str_replace("%2e", "/", $val);
      $val = str_replace("%2d", "-", $val);
      $val = str_replace("%2b", "+", $val);
       /**        *Spanish Characters    - Start     */
          $val = str_replace("A%F1", "ñ", $val);
          $val = str_replace("%E1", "a", $val);
          $val = str_replace("%E9", "e", $val);
          $val = str_replace("%ED", "i", $val);
          $val = str_replace("%F3", "o", $val);
          $val = str_replace("%FA", "u", $val);
       /**        *Spanish Characters    - End    */
      return $val;
   }
ISC 6.1.1 Multi-Vendor Edition

CharlieFoxtrot
Confirmed
Confirmed
Posts: 413
Joined: Sun Aug 09, 2009 1:23 pm

Re: [SEO] MakeURLSafe and the '/' character

Post by CharlieFoxtrot »

Wonderful!

Can this also be used to fix the ugly "%252d" that ISC inserts into a URL when the product name contains a dash? If so, how?

If not... where would I start my search to correct the problem of ugly/unreadable URL's that contain "%252d"?

I see that this annoying issue has been brought-up by users of the ISC forums... but true-to-form, it's been largely ignored by ISC.

~ Charlie
ISC 4.0.7

"... and let's be honest that whole "by design" thing is getting old too."

CharlieFoxtrot
Confirmed
Confirmed
Posts: 413
Joined: Sun Aug 09, 2009 1:23 pm

Re: [SEO] MakeURLSafe and the '/' character

Post by CharlieFoxtrot »

I just noticed... the following line of code appears twice:

Code: Select all

$val = str_replace("+", "%2b", $val);
Is there a reason for this? Or was is an error in the original code (that was also copied into the modified code?)
ISC 4.0.7

"... and let's be honest that whole "by design" thing is getting old too."

Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: [SEO] MakeURLSafe and the '/' character

Post by Martin »

CharlieFoxtrot wrote:Is there a reason for this? Or was is an error in the original code (that was also copied into the modified code?)
It was original code...

CharlieFoxtrot
Confirmed
Confirmed
Posts: 413
Joined: Sun Aug 09, 2009 1:23 pm

Re: [SEO] MakeURLSafe and the '/' character

Post by CharlieFoxtrot »

Martin wrote:
CharlieFoxtrot wrote:Is there a reason for this? Or was is an error in the original code (that was also copied into the modified code?)
It was original code...
I figured as much... harmless enough... but a bit sloppy. (Unless they wanted to make doubly certain that the replacement had been made.) ;)
ISC 4.0.7

"... and let's be honest that whole "by design" thing is getting old too."

netjet
Posts: 74
Joined: Tue Nov 03, 2009 12:03 pm

Re: [SEO] MakeURLSafe and the '/' character

Post by netjet »

Hi guys,

I'm very happy to discover this forum!
I'm using ISC 5.05 and I have a problem with the URL since I have my website in french.
Each time I'm using "é" or "è" characters I have a bad URL for spiders, for example the words tuyères shows like this Tuy%C3%A8res/
I have moded config.php file following the code for spanish but still do not work, could you help me with the problem?

thanks

netjet
Posts: 74
Joined: Tue Nov 03, 2009 12:03 pm

Re: [SEO] MakeURLSafe and the '/' character

Post by netjet »

I did it, it works great

Thank you

Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: [SEO] MakeURLSafe and the '/' character

Post by Martin »

netjet wrote:I did it, it works great

Thank you
If you found a solution then it would be useful if you could share it... There's not many non-English speakers (as first a first language) on here so any insights you have would doubtless be very useful to others in the same position.

netjet
Posts: 74
Joined: Tue Nov 03, 2009 12:03 pm

Re: [SEO] MakeURLSafe and the '/' character

Post by netjet »

Martin you are right, sorry I should have thought about it!

Here is the changes I've done for adapting it to french langage:

Code: Select all

   function MakeURLSafe($val)
       {
          $val = str_replace("-", "%2d", $val);
          $val = str_replace("+", "%2b", $val);
          $val = str_replace("+", "%2b", $val);
          $val = str_replace("/", "%2f", $val);
           /**        *French Characters    - Start     */
              $val = str_replace("ñ", "n", $val);
              $val = str_replace("á", "a", $val);
              $val = str_replace("é", "e", $val);
              $val = str_replace("è", "e", $val);
              $val = str_replace("ê", "e", $val);
              $val = str_replace("ú", "u", $val);
           /**        *French Characters    - End    */
          $val = urlencode($val);
          $val = str_replace("+", "-", $val);
          return $val;
       }

       /**
        * Convert an already search engine friendly based string back to the normal text equivalent.
        *
        * @param string The search engine friendly version of the string.
        * @return string The normal textual version of the string.
        */
       function MakeURLNormal($val)
       {
          $val = str_replace("-", " ", $val);
          $val = urldecode($val);
          $val = str_replace("{47}", "/", $val);
          $val = str_replace("%2f", "/", $val);
          $val = str_replace("%2e", "/", $val);
          $val = str_replace("%2d", "-", $val);
          $val = str_replace("%2b", "+", $val);
           /**        *French Characters    - Start     */
              $val = str_replace("A%F1", "ñ", $val);
              $val = str_replace("%E1", "a", $val);
              $val = str_replace("%E9", "e", $val);
              $val = str_replace("%C3%A8", "e", $val);
              $val = str_replace("%C3%AA", "e", $val);
              $val = str_replace("%FA", "u", $val);
           /**        *Spanish Characters    - End    */
          return $val;
       }
However the french langage is not 100% ok because I still have problems encoding " ' " , but well it's much better than before

Post Reply