How to Make URL Friendly

Asked

Viewed 1,385 times

1

I’m using the Framework Yii and need to create URLs friendly.

Example of URL: http://meudominio.com/meuControle/minhaView
Which is equivalent to: http://meudominio.com/index.php?r=meuControle/minhaView

In the config/main.php have enabled:

'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>',
    ),
),

However when I try to access a page using the Friendly URL, I get the following feedback:

404 Not Found

Nginx/1.4.6 (Ubuntu)

How do I resolve this situation?

1 answer

2


Amendments made to the config/main.php, you will need to change the settings on the server Nginx.

In the archive /etc/nginx/conf.d/default.conf or your server file in the folder /etc/nginx/sites-available/ add:

location / {
    index index.php;
    try_files $uri $uri/ /index.php?$args;
}

#Bloqueia o acesso direto às pastas do Yii
location ~ ^/(app|framework|themes/\w+/views){
    deny all;
}

#Bloqueia o acesso direto aos recursos estáticos
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    try_files $uri =404;
}

And finally, restart the service.

# service nginx restart

For more information, documentation in English.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.