how to remove dot and comma from entry-url

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
peggylon
Regular
Posts: 51
Joined: Tue Jul 01, 2008 6:32 pm
Location: Berlin
Contact:

how to remove dot and comma from entry-url

Post by peggylon »

Hi,

I'm using the permalink structure as suggested. I saw, that commas and dots are left in the entry url, whilst : and ' are removed. How can I achieve, that commas , and dots . are also removed?

On my website I link to various blog entries, using the same url structure, but without any sign which isn't [-,a-z,0-9].
To not get two different urls with same content google-indexed, I'd like to change s9y-generated links accordingly.

Brief example:

my entry headline: Fremdgekocht: Quinoa mit Mandarine u. Paranuss

my link-url: http://www.multikulinarisch.es/?/archives/65-Fremdgekocht-Quinoa-mit-Mandarine-u-Paranuss.html

s9y-url: http://www.multikulinarisch.es/?/archives/65-Fremdgekocht-Quinoa-mit-Mandarine-u.-Paranuss.html

Is there a chance of using the same php-function for link-generation on s9y headlines I use externally?
If not how/where can I adjust s9y-functionality to achieve same url?
----------
peggylon aka multikulinaria http://www.multikulinarisch.es
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: how to remove dot and comma from entry-url

Post by garvinhicking »

Hi!

The way to achieve this is to set two variables inside your serendipity_config_local.inc.php file for example:

Code: Select all

$GLOBALS['i18n_filename_from'] = array(',', '.');
$GLOBALS['i18n_filename_to'] = array('', '');
This will replace commas and dots to an empty string. This is then accessed in the serendipity_makeFilename() function found in include/functions_permalinks.inc.php.

If you want to get your hands dirty, you could replace that function with your own one.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
peggylon
Regular
Posts: 51
Joined: Tue Jul 01, 2008 6:32 pm
Location: Berlin
Contact:

Re: how to remove dot and comma from entry-url

Post by peggylon »

Thanks a lot, Garvin!
You guys are doing a great job here... :D
----------
peggylon aka multikulinaria http://www.multikulinarisch.es
stm999999999
Regular
Posts: 1531
Joined: Tue Mar 07, 2006 11:25 pm
Location: Berlin, Germany
Contact:

Re: how to remove dot and comma from entry-url

Post by stm999999999 »

I tried it and all dots and comma are away, but all my spaces are replaced by empty strings, before they were replaced by "-"? (which looks better I think).
Ciao, Stephan
johncanary
Regular
Posts: 116
Joined: Mon Aug 20, 2007 4:00 am
Location: Spain
Contact:

Re: how to remove dot and comma from entry-url

Post by johncanary »

garvinhicking wrote:

Code: Select all

$GLOBALS['i18n_filename_from'] = array(',', '.');
$GLOBALS['i18n_filename_to'] = array('', '');
And how could I force the {$entry.link} to be all lower case (just for display purposes)?

No idea if you have seen my post SEO / Permalinks / Duplicate Content

Yours
John

Update: Looks like messing with ./functions_permalinks.inc.php should
do the trick. I guess I can figure it out.

Have a nice weekend.
Yours John
: John's Google+ Profile
: John's E-Biz Booster Blog powered by Serendipity 1.7/PHP 5.3.14
johncanary
Regular
Posts: 116
Joined: Mon Aug 20, 2007 4:00 am
Location: Spain
Contact:

Re: how to remove dot and comma from entry-url

Post by johncanary »

@stm999999999 I have the answer for you.

When you configure those arrays in the local configuration file it replaces
the arrays defined inside the function. It does not add to it. Hence the change from space to hyphens disappeared.

You could see this as feature or as bug.
(What do you think Garvin?)


How I get my lower case URLs and remove , . ! etc.

At first I wanted to add the strtolower function to
function serendipity_makeFilename() in the file
./include/functions_permalinks.inc.php

But there is no need for. I simply assigned the proper arrays as pointed to
by Garvin in the configuration files.

Here they are. Add this to your local configuration file (at your own risk; no warranties)

Code: Select all

/** # $Id: add to: serendipity_config_local.inc.php 2009-04-27 16:57:00Z john W. Furst $
 * Add this to your local configuration file
 *     ./serendipity_config_local.inc.php
 *
 * Replaces the default strings used in the file
 *     ./include/functions_permalinks.inc.php in the funtion
 *     function serendipity_makeFilename ();
 *     (Specifying those arrays here, does not add to but replaces the arrays
 *     assigned in the php file.)
 * ---------------------------------------------
 * For dealing with unwanted characters in URLs.
 *    All characters to lower-case AND add those characters for
 *    replacement [!%_+,;.:?] by "-"
 *
 * When changing the local configuration file. Always double check
 * that the read permissions are set to -rw-------. It contains your
 * database login info, should not be readable by others!
 *
 * This is provided as is. Feel free to use and modify it at your own risk.
 * Copyright (C)2009 by John W. Furst
 *
 * How to test?
 * (1) Modify the local configuration file. (2) Start a new blog post, write in
 * the title. (3) Do a preview (without saving) and (4) check the URL in the
 * status bar of your browser. As Easy as that.
 */

$GLOBALS['i18n_filename_from'] = array(
    ' ', '!', '%', '_', '+', ',', ';', '.', ':', '?',
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
    'Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', 'ß', 'é', 'è', 'ê', 'í', 'ì', 'î', 'á', 'à', 'â', 'å', 'ó', 'ò', 'ô', 'õ', 'ú', 'ù', 'û', 'ç', 'Ç', 'ñ', 'ý');

$GLOBALS['i18n_filename_to'] = array(
    '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
    'ae', 'ae', 'oe', 'oe', 'ue', 'ue', 'ss', 'e', 'e', 'e', 'i', 'i', 'i', 'a', 'a', 'a', 'a', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'c', 'c', 'n', 'y');
I actually translate the characters space ! _ + , ; . : ? to hyphens, hence they
are separators. (Multiple, consecutive hyphens in a row are reduced to just one by the way.)

This solution is absolutely upgrade safe because it does not change any Serendipity program files.

Additional notes:
  • When saving the file beware of your file encoding! So the special characters äöü... are not messed up. E.g. I found my s9y installation files are iso-8859-1 encoded while
    I use utf-8 usually.
  • When changing an existing blog you'll need to make sure the old URLs are still working, e.g. by changing the .htaccess file.
  • Some changes in the blog configuration might overwrite your modifications in the .htaccess file. Log and backup your changes.
  • You can force an update of all links kept in the table permalinks, e.g. by changing the permalink structure and reverting back. That's at least how I did it.

More details about the changes on my blog and
why I have implemented them can be found

** here in this forum: SEO / Permalinks / Duplicate Content

** and on my now -- better SEO optimized-- S9Y blog: SEO Friendly Permalink Structure
Yours John
: John's Google+ Profile
: John's E-Biz Booster Blog powered by Serendipity 1.7/PHP 5.3.14
peggylon
Regular
Posts: 51
Joined: Tue Jul 01, 2008 6:32 pm
Location: Berlin
Contact:

Re: how to remove dot and comma from entry-url

Post by peggylon »

Sorry stm999999999, I missed your post. Just stumbled upon it today, when searching for redirect-topic (to avoid duplicate content after url rewriting;
see http://board.s9y.org/viewtopic.php?f=2&t=18080).
Thanks for your help!

Peggy
----------
peggylon aka multikulinaria http://www.multikulinarisch.es
Post Reply