i want only SanphamController to have from this:
mySite/sanpham/chitiet/slug/nuoc-hoa-phap-vuiton.html
to
mySite/nuoc-hoa-phap-vuiton.html
i have dealed it but all other Controller (CartController,etc,..) in my site not run anymore, it think the controller is an item in SanPhamController.
This is my code
.htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
In main/config.php:
'urlManager' => array(
'rules' => array(
'/'=>'site/index',
'<view:(gioi-thieu|huong-dan|hinh-thuc-thanh-toan|dieu-khoan-dich-vu|chinh-sach-dich-vu)>' => 'site/page',
'<action:(lienhe|thanhtoan|dangnhap|dangky|dangxuat)>' => 'site/<action>',
'danh-muc/<slug:.*>'=>'sanpham/danhmuc',
'thuong-hieu/<slug:.*>'=>'sanpham/thuonghieu',
'tim-kiem/<slug:.*>'=>'sanpham/timkiem',
'<slug:.*>' => 'sanpham/chitiet',
'<controller:\w+>/<id:\d+>' => '<controller>/chitiet',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
'urlFormat' => 'path',
'urlSuffix' => '.html',
'showScriptName' => false,
),
Simply add this rule at the top of url manager array:
"nuoc-hoa-phap-vuiton"=>"sanpham/chitiet/slug/nuoc-hoa-phap-vuiton"
Related
I'm trying to map services/v2/ to servicesV2.
I tried:
'services/v2' => 'servicesV2',
And I tried:
'services/v2/' => 'servicesV2/',
And:
'services/v2/<action:\w+>' => 'servicesV2/<action:\w+>',
And I got an error:
The system is unable to find the requested action "v2".
Did you put it on the begin of the array?
'rules' => array(
'services/v2' => 'servicesV2',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
So using yii I want to have urls like this:
mydomain.com/some-short-slug
And this url to map the following:
mydomain.com/book?bookslug=some-short-slug
How can I do this?
You need do this inside url-manager:
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'caseSensitive' => false,
'rules' => array(
...
'<slug>'=>'book/index'
...
),
Now, if url like mydomain.com/some-short-slug, you have $slug equal to "some-short-slug" in the actionIndex of BookController
When using the
Yii::app()->createUrl('/page/');
it is additing additional trailing slash to the url LIKE http://www.sitename// AND http://www.sitename//page
That I need to exclude two slashes, Application url manager is as follow,
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'urlSuffix' => '/',
'rules' => array(
'site/news_letter_unsubsubscribe/<id:\w+>' => 'site/news_letter_unsubsubscribe',
'page/<id:[\w\-]+>' => 'page/index/',
'site/blog_detail/<id:[\w\-]+>' => 'site/blog_detail',
'location/<id:[\w\-]+>' => 'location/index',
'auth/partner_detail/<id:[\w\-]+>' => 'auth/partner_detail',
//'tour/tour_detail/<id:\w+>/<date:\w+>'=>'tour/tour_detail',
'activity/activity_detail/<id:[\w\-]+>' => 'activity/activity_detail',
'activity/compare_detail/<id:[\w\-]+>' => 'activity/compare_detail',
'tour/tour_detail/<id:[\w\-]+>' => 'tour/tour_detail',
'tour/compare_detail/<id:[\w\-]+>' => 'tour/compare_detail',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'auth/reset_password/<id:\w+>' => 'auth/reset_password',
'site/linkedin_login/<id:\w+>' => 'site/linkedin_login',
),
)
.htaccess rules
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
In Yii2 your code is wrong. You are reading doc! Example:
echo \Yii::$app->urlManager->createUrl('page');
I could sort this issue removing the suffix slash from request base url
Thanks
I have url: /profile/profileBase/index where "profile" is module, "profileBase" is controller and "index" is action.
I want to url manager would accept route like: /profile/read/index
where "read" could be alias of controller.
Is there any way to do this using url manager rules?
Thanks
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'profile/read/index '=>'profile/profileBase/index'
),
),
You should simply add the following rule in urlManager config :
'profile/read/index'=>'profile/profileBase/index',
I have an encrypted parameter in ZF2 routing that has "/" in it for e.g:
http://domain.com/request/$2y$14$OmovR9wA1TnBG2fxdKuU9ORYTPGChgfyesGVxilP74**/**2F2t8eJgbNF2
On submit of this request the URL turns to
http://domain.com/request/$2y$14$OmovR9wA1TnBG2fxdKuU9ORYTPGChgfyesGVxilP74**%**2F2t8eJgbNF2
this causes a problem an apache server throws an error saying page not found. Is there a way from where i can stop converting the "/" to "%" in the parameter field. My .htaccess file is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
EDIT
Route code:
'exampleroute' => array(
'type' => 'segment',
'options' => array(
'route' => '/exampleroute/[:regexparameter]',
'constraints' => array(
'regexparameter' => '[$.a-zA-z0-9_-]*',
),
'defaults' => array(
'__NAMESPACE__' => 'Mynamespace\Controller',
'controller' => 'exampleroute',
'action' => 'example',
),
),
),
I had to add "%2F" => "/" in Zend\Mvc\Router\Http\Segment File in ZF2 library. Now its working fine