0

What i am trying to do is to create a custom rule in Yii for URL management.

The general URL rules are set in main.php

    'urlManager'=>array(
        'urlFormat'=>'path',
                    'showScriptName'=>false,
        'rules'=>array(
            '<controller:\w+>'=>'<controller>/index',
                            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),

the .htaccess file is also set like

RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php
RewriteRule . index.php

so i have URLs in the form

local/cp/xyz/create

Now i have a custom controller for which the current URL is like

local/cp/xyz/create/abc

what i want is

local/cp/abc/create

1 Answer 1

1

Assuming 'local/cp' is your application url, 'xyz' is the controller and 'abc' is some kind of variable (I'll call it myVar), you'd need a rule like so:

'<myVar:\w+>/<action:\w+>'=>'xyz/<action>',

or

'<myVar:\w+>/create'=>'xyz/create',
Sign up to request clarification or add additional context in comments.

1 Comment

Sort of.. Actually i got it working. What i had to use was, '<_mod:(abc|cbd)>/<_ac:(create|delete)>' => 'xyz/<_ac>/<_mod>', It got hard to explain my question.

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.