PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 23, 2022

[FIXED] yii url manager with 2 params

 January 23, 2022     .htaccess, php, yii, yii-url-manager     No comments   

Issue

I would like to create an url like this: http://domain.com/index.php/hir/2015-02-12/news_title

Here is my urlmanager what doesn't work:

 'urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
        'hir/<date:\d+>/<title:\w+>'=>'news/view',
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ),
  ),

And here is my .htaccess:

Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
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
</IfModule>
RewriteEngine on

Solution

No need to .htacces file, you can solve this by url-manager. Just change your first url-manager rule like this:

'hir/<date:\d+>/<title:\w+>'=>'news/view' TO 'hir/<date>/<title>'=>'news/view'

I think this will help you.



Answered By - hamed
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing