php - Configuring urlManager Rules in Yii2 -


i'm new using yii2 , have been using urlmanager, have following code, works fine think should shorter. have couple rules follows :-

    'rules' => [                 'gifts/<subjectone:[\s\s]+>/<subjecttwo:[\s\s]+>' => 'gifts/index',             'gifts/<subjectone:[\s\s]+>/<subjecttwo:[\s\s]+>/' => 'gifts/index',             'gifts/<subjectone:[\s\s]+>' => 'gifts/index',             'gifts/<subjectone:[\s\s]+>/' => 'gifts/index',      ]; 

as can see i've added 4 rules go same page handle different situations.

i've had add same url's twice, once / , 1 without stop 404's. please advise of better way handle this.

you can add +|(\/?) @ trailing of rule. take look:

 'gifts/<subjectone:[\s\s]+>+|(\/?)' => 'gifts/index', 

so there no need write rules twice.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -