Accented characters in URL and 404 error

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Accented characters in URL and 404 error

Post by nervino »

I've upgraded an old cmsms site (1.10) to cmsms 2.1.3. In this site I had a module where I handled pretty urls in this way:

MyModule.module.php:

Code: Select all

function InitializeFrontend() {

// All
$this->RegisterRoute('/[MyModule\/(?P<IDart>[0-9-]+)_(?P<returnid>[0-9]+)_l(?P<filter_loc>[0-9]+)_t(?P<filter_tipo>[0-9]+)\/(?P<order_by>[a-z]+)\/(?P<filter_period>[A-Za-z0-9-]+)\/(?P<aliased_title>[A-Za-z0-9-]+)$/',array('action'=>'art_detail'));

//only with order_by
$this->RegisterRoute('/[MyModule\/(?P<IDart>[0-9-]+)_(?P<returnid>[0-9]+)\/(?P<order_by>[a-z]+)\/(?P<aliased_title>[A-Za-z0-9-]+)$/',array('action'=>'art_detail'));

etc...
and I create pretty urls in action.default.php like so:

Code: Select all

$aliased_title = munge_string_to_url($row['Title'],true);
In new CMSMS 2.x accented characters are allowed, hence my urls have them, but those links lead to a 404 error.

I'm not able to find the reason why. Could someone give suggestions about this issue?

I also tried to use the method used in News module:

Code: Select all

$route = new CmsRoute('/[MyModule\/(?P<IDart>[0-9-]+)_(?P<returnid>[0-9]+)_l(?P<filter_loc>[0-9]+)_t(?P<filter_tipo>[0-9]+)\/(?P<order_by>[a-z]+)\/(?P<filter_period>[A-Za-z0-9-]+)\/(?P<aliased_title>[A-Za-z0-9-]+)$/',array('action'=>'art_detail'));
    cms_route_manager::add_dynamic($route);
but it works only if use it for one url; if I use this method for routing all pretty urls I always got 404 errors.

Furthermore (please have pity) which is the convenience of using add_static vs add_dynamic routes ?

Thank you
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: Accented characters in URL and 404 error

Post by Jeff »

My guess the problem is that Accented chars don't fall into A-Za-z, I am not familiar with them enough to how to include them. Maybe google search "regex accented characters".

Do you need the aliased title from the url? In my modules I have the title in the URL for SEO but in the route I copy what News does and put it in junk with "\/(?P<junk>.*?)$/" and ignore it.

Registering your routes statically allow your module to be lazy loaded (only loaded when it is actually called on the page) and has less overhead for each individual page load. If you have a small module and/or use only a few generic regex route it probably won't be a noticeable difference.
Post Reply

Return to “Developers Discussion”