Page 1 of 2

[SEO] MakeURLSafe and the '/' character

Posted: Wed Jul 22, 2009 2:31 am
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.

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

Posted: Fri Aug 14, 2009 12:15 am
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;
   }

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

Posted: Fri Aug 14, 2009 12:43 pm
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

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

Posted: Fri Aug 14, 2009 1:53 pm
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?)

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

Posted: Fri Aug 14, 2009 9:29 pm
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...

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

Posted: Fri Aug 14, 2009 9:32 pm
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.) ;)

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

Posted: Tue Nov 03, 2009 12:11 pm
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

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

Posted: Tue Nov 03, 2009 1:13 pm
by netjet
I did it, it works great

Thank you

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

Posted: Mon Nov 09, 2009 9:47 pm
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.

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

Posted: Tue Nov 10, 2009 11:00 am
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