-1

I have module in the frontend, and I want to make a friendly url like:

//yourdomain/a-zA-Z_module-controller-action-id-page-1.html

such as like this link:

http://kudufood.com/com-van-phong-lam-the-nao-de-nau-canh-bong-cai-duoc-ngon-kudu_cookbooks_1429067720.html
arogachev
  • 33,150
  • 7
  • 114
  • 117

1 Answers1

0

You can enable pretty URLs by adding the following code to your application components in config/web.php and configure custom URLs in 'rules':

'components' => [
    'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName'=>true,
        'rules' => [
            // your rules go here
            'customURL'=>'my-controller/my-action'
        ],

If you wish to hide index.php as well, then set:

 'showScriptName'=>false

and create an .htaccess file your /web directory with the following contents:

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

Documentation: http://www.yiiframework.com/doc-2.0/yii-web-urlmanager.html

NovaLogic
  • 658
  • 13
  • 21
  • My problem is not make a friendly url in the controller. I want to make a friendly on the module. And an other thing is: I do not want to have the forward slash "/" . I would like to be like this: h.t.t.p://yourdomain/a-zA-Z_module-controller-action-id-page-1.html – Godness Vu Apr 24 '15 at 00:46
  • 1
    You are looking for something like this maybe: '/' => '/default/', '//' => '/default/', '/' => '//index', '//' => '//' See: http://stackoverflow.com/questions/27402923/custom-url-rules-with-modules-in-yii2 – NovaLogic Apr 24 '15 at 18:25