Skip to main content

What is URL moniker in ocPortal CMS

URL moniker is simply the name for a "nice address" of web page on ocPortal powered site. In current ocPortal version, v7.1.5, length of url monikers is limited to no more than 24 characters for a page part and 255 characters for the whole URL moniker.

Unfortunately, there is not any configuration option in Administration zone, so we made changes manually to support longer URL monikers on site we're working on -, a portal dedicated to female population. Maybe you would like to have this feature, so here is tutorial for that.

- Advertisement -

How to change ocPortal code to support longer URL monikers

1) Copy file sources/urls2.php into sources_custom/urls2.php

You do not need to change core files directly because they could be overridden during the next updates. So instead, all your modifications in code and theme files should be copied to appropriate _custom folder and changed there. All modifications will be treated as they were made in core files.

2) Open file sources_custom/urls2.php

3) Find function _choose_moniker and the following code inside:

if (strlen($moniker)>24) 
    if (($pos===false) || ($pos<12)) $pos=24; 

- Advertisement -
- Advertisement -

4) Replace the code with the following modification:

$max_moniker_length = 100; 
if (strlen($moniker)>$max_moniker_length) 
    if (($pos===false) || ($pos<$max_moniker_length-12)) $pos=$max_moniker_length; 

5) Save the changes

Great! Your ocPortal powered website now has support for URL monikers with length of 100 characters per page. Much longer than original 24, isn't it ;) You are free to set even larger number for max_moniker_length value.

OK, new monikers will be longer, but what about already existing monikers in the system? Well, you have two options described below. But be careful, if search engines crawled your site, that could impact its position in searching results. In fact, all links to your site made on other sites will not work. So this step is recommended when your site is not famous yet.

- Advertisement -

How to change/recreate URL monikers in ocPortal

There's not such option as monikers configuration in ocPortal so far.

The first way you could do is to manually update m_moniker fields in table ocp_url_id_monikers.

The second one is much better if you do not have many records in the table. You simply need to delete all records in table ocp_url_id_monikers and they will be automatically recreated next time you or a visitor visits site. The following SQL code in phpMyAdmin will remove all records in the table:

DELETE FROM `ocp_url_id_monikers`

- Advertisement -

How to change varchar field length in MySQL

The next problem could be length of a table field that keeps monikers in ocPortal. Currently, it is m_moniker - varchar(255). This means that the field is able to keep url with 255 characters (only). Note that varchar's length was 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. So we could easily change this if (and only if!) your MySQL version is 5.0.3+:

1) Login to phpMyAdmin and go to a database

2) Select table ocp_url_id_monikers in the sidebar

3) Click Structure in the top menu

4) Click Change in Action column for field m_moniker

5) Set field Length/Values to 1024, instead of 255

6) Save the changes

Your table field now supports strings longer than 255 characters!

You can check described behavior in action on our site, portal and forums for women.

- Advertisement -