1

I have a little question regarding the routing with Zend Framework 2. URLs with "normal" letters are working fine and I get to my sides, but for example an URL with characters like á or whitespaces /test/some characters /test/héllo won't work and I get a 404-Error. When I remove the whitespaces in the url or replace the special character é with normal "e" I will get my url too.

So I think the problem is in my module.config.php with the constraints. How can I define these special characters to reach the URLs? Hope you can help me!

module.config.php URL Segment

'chemistry' => array(
    'type' => 'Segment',
    'options' => array(
        'route' => '[/:id[/:name]]/chemistry/page[/:page]',
        'constraints' => array(
            'id'    => '[0-9]*',
            'name'  => '[a-zA-Z][a-zA-Z-]*',
            'page'  => '[0-9]*'
        ),
        'defaults' => array(
            'action'=> 'chemistry',
            'id'    => '1',
            'name'  => 'Messi',
            'page'  => '1'
        ),
    ),
),
Hans Martin
  • 337
  • 1
  • 13

1 Answers1

0

You are using a regex in your route constraints. If you want to match route segments like that you should change your regex constraint accordingly. So if you want to match a route segment with a space character you have to add it to your regex:

  • To match spaces anywhere in the segment:

    '[a-zA-Z ]+'

  • To match words with spaces in between.

    '[a-zA-Z]+( [a-zA-Z]+)*'

You can read more on Regex in routing here in the paragraph Zend\Mvc\Router\Http\Regex in chapter Routing

Wilt
  • 41,477
  • 12
  • 152
  • 203