0

I am working with advanced project application and trying to add URL rules in Yii2 to handle custom URLs with dashes.

What I want to do is to change the URL from

http://www.example.com/post/details?url=example-post-title

To

http://www.example.com/example-post-title

I have below configuration which works fine when the URL parameter does not have dash (exampleposttitle).

'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
        // ...
        '<url:\w+>' => 'post/details',
    ],
],

1 Answer 1

5

You need to fix your regexp, since \w+ does not allow dashes:

'<url:[\w-]+>' => 'post/details',
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.