Workaround: Use of hyphens instead of underscores in declarative URLs

Sebastian Tänzer <[email protected]>
Newsgroups gmane.comp.cms.zms.devel
Message-ID <[email protected]>
Even though Google announced to equally "read" URLs with underscores  
(alike URLs with hyphens) nothing has changed yet.

In recent projects we noticed a dramatic PageRank and search ranking  
increase in general for URLs we changed from multiple terms to only  
one term (i.e. webdesign_bonn to webdesign) But in terms of SEO the  
best solution would have been a URL like "mydomain.de/webdesign-bonn"  
- but ZMS's own id_quote function replaces all hyphens with underscores.

A workaround for this problem is:

Edit _globals.py (around line 180) and add the new function idurl_quote:

def idurl_quote(s):
   mapping = {
         '\x20':'-',
         '/':'-',
         unicode('\xe4','latin-1').encode('utf-8'):'ae',
         unicode('\xf6','latin-1').encode('utf-8'):'oe',
         unicode('\xfc','latin-1').encode('utf-8'):'ue',
         unicode('\xc4','latin-1').encode('utf-8'):'Ae',
         unicode('\xd6','latin-1').encode('utf-8'):'Oe',
         unicode('\xdc','latin-1').encode('utf-8'):'Ue',
         unicode('\xdf','latin-1').encode('utf-8'):'ss',
   }
   for key in mapping.keys():
     s = s.replace(key,mapping[key])
   valid = [ord('-')]+ [ord('_')] + range(ord('0'),ord('9')+1) + range 
(ord('A'),ord('Z')+1) + range(ord('a'),ord('z')+1)
   s = filter( lambda x: ord(x) in valid, s)
   while len(s) > 0 and s[0] == '_': s = s[1:]
   s = s.lower()
   return s

Edit _zmsglobals.py (around line 412) and add theses lines:

     def idurl_quote(self,s):
       return _globals.idurl_quote(s)

(right after the existing id_quote function)

Edit zmsobject.py (around line 545) and change this line

declId = self.id_quote( declId)

to

declId = self.idurl_quote( declId)

I hope this helps someone who's having the same problem and needs a  
workaround until ZMS is not going to replace hyphens anymore.
Keep in mind that this workaround changes all "_" in your URLs to "-"  
and a lot of your links indexed by Google might stop working.

Mit freundlichen Grüßen / yours sincerely

Sebastian Tänzer
amcm web e.K.

Beratung und Entwicklung für Internetlösungen
Web solutions, consulting and development

c/o amcm GmbH
Kekuléstr. 39
53115 Bonn
Germany

Tel +49-228-33646-23
Fax +49-228-33646-13

[email protected]
http://www.amcm.de
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.