Answer the question
In order to leave comments, you need to log in
Yii + Nginx "rewrite in rewrite"
Hello.
Please tell me how to write this rule correctly:
location ~ ^/(aaa|bbb|ccc) {
try_files $uri $uri/ /$yii_bootstrap?$args;
}
location ~ ^/([a-zA-Z0-9_-]+$) {
rewrite ^/([a-zA-Z0-9_-]+$) /bbb/?str=$1 last;
}
Meaning of the code: If we request a link with aaa, bbb or ccc controller, then we get to the controller. If another arbitrary link is requested, then we get to the controller with parameter substitution.
Everything works if sent to a regular link /bbb.php?str=, but under this condition the variable goes as a controller and works:
try_files $uri $uri/ /$yii_bootstrap?$args;
Thanks for any hint.
Answer the question
In order to leave comments, you need to log in
Via yii route means
in config/yii
'components'=>array(
...
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'/'=>'',
array('/aaa/default/index/id/58058', 'caseSensitive'=>false, 'pattern' => 'aaa', 'verb' => 'GET', 'parsingOnly' => true),
array('/bbb/default/index', 'caseSensitive'=>false, 'pattern' => 'bbb.php', 'verb' => 'GET', 'parsingOnly' => true),
array('/bbb/default/index', 'caseSensitive'=>false, 'pattern' => 'bbb', 'verb' => 'GET', 'parsingOnly' => true),
array('/ccc/default/index', 'caseSensitive'=>false, 'pattern' => 'ccc', 'verb' => 'GET', 'parsingOnly' => true),
),
),
),
'components'=>array(
...
'errorHandler' => array(
// use 'site/error' action to display errors
'errorAction' => 'site/error',
),
),
public function actionError()
{
$error=Yii::app()->errorHandler->error;
if($error) {
if(Yii::app()->request->isAjaxRequest){
echo $error['message'];
Yii::app()->end();
} else {
if(!empty($error['code']) && $error['code'] == 404 && !empty($error['traces'][0]['args'][0]))
{
echo 'Query : '.$error['traces'][0]['args'][0];
$this->redirect(array('bbb/index','str'=>$error['traces'][0]['args'][0]));
}
echo $error['message'];
}
}
location / {
try_files $uri $uri/ /index.php?$args;
root /var/www/site;
index index.php index.html index.htm;
}
location ~ \.php$ {
try_files $fastcgi_script_name =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass PollFPM;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/site$fastcgi_script_name;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question