1
votes

I want to be able to map definite string values such 'index.html' on URLs such mydomain/index.php?r=page/view&id=1. Id/value pairs should be stored in the database, therefore hardcoding urlManager rules in the /config/main.php is unsuitable for my purposes. I'm using yii-1.1.16.

2
I think Faking url suffix can solve your problem. Please refer this link for more information. - hamed

2 Answers

1
votes

Try to change url-manager to this:

'urlManager'=>array(
    'urlFormat'=>'path',
    'urlSuffix'=>'.html',
    'caseSensitive'=>false
    'rules'=>array(
        'pattern1'=>array('<controller:page>/<action:view>/<id:\d+>', 
    ),  

),

This can be helpful.

Update:

If you want to map /index.php/page/view/id/1 url to mydomain/about.html, you need to do following works:

1.Remove index.php from url: For removing index.php, you can easily refer to this link. Then you need to enable apache RewriteModule in httpd.conf.

2.Add a rule in url-manager: I updated the url-manager rule and now this is look like this:

'urlManager'=>array(
     'urlFormat'=>'path',
     'showScriptName' => false,
     'urlSuffix'=>'.html',
     'caseSensitive'=>false
     'rules'=>array(
         'about'=>'page/view/id/1',
         'pattern1'=>array('<controller:page>/<action:view>/<id:\d+>',
),  

),

Note that, no need to repeat index.php in all url-manager rules. Good luck!

0
votes

Now I trying to use faking url suffix.

'urlManager'=>array(
        'urlFormat'=>'path',
        'rules'=>array(
            'pattern1'=>array('<controller:page>/<action:view>/<id:\d+>', 
            'urlSuffix'=>'.html', 'caseSensitive'=>false)
        ),
    ),

When I enter URL '/index.php/page/view/id/1' it remains the same. 'mydomain/index.php/page/view/id/2' instead 'mydomain/1.html'