These are my rules for urlManager. It works only for controller 'vijesti'. When I try to open any other page it gives me 404 error.
Should I write my own class for urls or what? Could someone explain me what to do?
'<controller:(vijesti)>/<action:(admin|create|update|delete|trazi)>' => 'vijesti/<action>',
'<kategorija:\w+>/<naslov:\w+>'=>'vijesti/view',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
Problem:
the rule '<kategorija:\w+>/<naslov:\w+>'=>'vijesti/view' covers '<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
Try this:
'<controller:(vijesti)>/<action:(admin|create|update|delete|trazi)>' => 'vijesti/<action>',
'/<kategorija:\w+>/vw_<naslov:\w+>'=>'vijesti/view',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
try this:
'vijesti/<_a:(admin|create|update|delete|trazi|view)>' => 'vijesti/<_a>',
'<kategorija:\w+>/<naslov:\w+>'=>'vijesti/view',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
Related
On Yii 1.x
We found it quite difficult to implement a language selection option with Yii, so, we are using the following extension:
http://www.yiiframework.com/extension/langhandler/
Like so:
main.php URL Manager:
urlManager'=>array(
'class'=>'application.extensions.langhandler.ELangCUrlManager',
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<lang:(pt|en)>/<_c>/<_a>/' => '<_c>/<_a>',
),
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<controller:\w+>' => '<controller>/index',
),
When we click "en", instead of getting:
http://blabla.dev/experience/info/114?lang=en
We are getting:
http://blabla.dev/experience/info?lang=en
So the ID part of this url is being completely ignored.
Can anyone give us a hand here?
We have tried to change the rules to:
'<lang:(pt|en)>/<_c>/<_a>/<_i>/' => '<_c>/<_a>',
and a lot of other combinations, but that is just guessing.
I have a controller called "SitemapController". This easily maps to this url:
/sitemap
However, I need that link to also work if you open
/sitemap.xml
How do I map it in YII so the system can use both?
you can achieve it like below by editing config file ,
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'sitemap/*'=>'sitemap/index',
'sitemap.xml/*'=>'sitemap/index',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
Now it will map routes to sitemap/someKey/someValue/..
Add this to your url routing 'sitemap' => array('site/sitemap', 'urlSuffix'=>'.xml'),
You can modify your url manager in config/main.php this way,
'site/sitemap.xml'=>'site/sitemap',
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'site/sitemap.xml'=>'site/sitemap',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
In your .htaccess add this rule
RewriteEngine On
RewriteRule ^sitemap.xml.*$ http://example.com/sitemap/ [R=301,L]
I have controller and module with same name: download
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'http://'.SITE_DOMAIN.'/<action:(download)>/<url:.*>'=>'<action>',
'http://<module:(download)>.'.SITE_DOMAIN.'/<code:\w{32}>'=>'<module>',
),
)
So I want to links like: http://domain.com/download/dir1/dir2/file1.zip
to be routed to: application/controllers/DownloadController
where $_GET['url']=='dir1/dir2/file1.zip'
And links like: http://download.site.com/some_code
to be routed to: application/modules/download/controllers/DefaultController.php
where $_GET['code']=='some_code'
But now both types of links are routed to: application/modules/download/controllers/DefaultController.php
I can't understand why
Try with this:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'http://'.SITE_DOMAIN.'/download/<url:.*>'=>'Download/index',
'http://download.'.SITE_DOMAIN.'/<code:\w{32}>'=>'Download/Default/index',
),
)
Note: both URLs will be routed to the index action of they own controller.
I am trying to use the following url: (With the htaccess applied)
/user/{username}
to redirect to something like:
/user/view/{username}
I have no clue what the rule should be...
My current urlManager config is:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>array(
)
),
I'm also going to want some overrides such as (That go to the regular action)
/user/settings
/user/edit
etc... how would I add these?
Figured it out on my own!
'user/settings' => 'user/settings',
'user/<action>/*' => 'user/view/user/<action>',
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<view>' => array('site/page/view/'),
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
//'index' => array('site/index'),
),
),
I currently have that in my main.php file.
The problem I have is that when I view /index.php/index I have shown the index page in the pages folder but when I get to /index.php/about I still get the index.php file in the pages folder.
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
//'index' => array('site/index'),
'<view>' => array('site/page/view/'),
),
),
It should have been like this:
Now the rule should be (at least in version 1.1.12)
'<view:\w+>' => 'site/page',
This code will provide $_GET['view'] to SiteController::actionPage, e.g. http://example.com/test will set $_GET['view'] = 'test'