我在我的实时服务器上安装了yii,我们有两个接口,一个后端和一个前端。在后端,我们添加产品,在前端,为产品呈现视图。问题是,例如,这是我们的网站https://mmstore.be/products/714/IPhone-12-Mini-Scherm-Reparatie产品页面,如果你把任何东西在url的最后,如https://mmstore.be/products/714/IPhone-12-Mini-Scherm-Reparatie/03003300303094949949494,页面将保持不变,这意味着它应该显示未找到的页面,但相同的页面再次出现。
下面是我的配置文件代码前端。
<?php
$params = array_merge(
require __DIR__ . '/../../common/config/params.php',
require __DIR__ . '/../../common/config/params-local.php',
require __DIR__ . '/params.php',
require __DIR__ . '/params-local.php'
);
return [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'frontendcontrollers',
'components' => [
'request' => [
'csrfParam' => '_csrf-frontend',
],
'cache' => [
'class' => 'yiicachingFileCache',],
'user' => [
'identityClass' => 'commonmodelsUser',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
],
'session' => [
// this is the name of the session cookie used for login on the frontend
'name' => 'advanced-frontend',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yiilogFileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'baseUrl' => '',
'enablePrettyUrl' => false,
'showScriptName' => false,
'enableStrictParsing' => true,
'rules'=>array(
'<controller:w+>/<id:d+>' => '<controller>/view',
'<controller:w+>/<action:w+>/<id:d+>' => '<controller>/<action>',
'<controller:w+>/<action:w+>' => '<controller>/<action>',
'class' => 'yiiwebUrlNormalizer',
'collapseSlashes' => true,
'normalizeTrailingSlash' => true,
),
],
],
'params' => $params,
];
我有error.php在我的网站目录,下面是它的代码
<?php
/* @var $this yiiwebView */
/* @var $name string */
/* @var $message string */
/* @var $exception Exception */
use yiihelpersHtml;
$this->title = $name;
?>
<h1><?= Html::encode($this->title) ?></h1>
<div class="alert alert-danger">
<?= nl2br(Html::encode($message)) ?>
</div>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
Please contact us if you think this is a server error. Thank you.
</p>
很奇怪,您禁用了" enableprettyurl ",而使用了" pretty url "。如果"/产品/";是控制器名称,假设"iphone -12- mini - scherm - reparatie";是一个名为"url"然后你可以这样修改urlManager:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'/'=>'site/index',
'/products/<id>/<url>'=>'products/view',
'/products/<id>'=>'products/view',
'<controller:w+>/<action:w+>' => '<controller>/<action>',
],
],
控制器中的应该是这样的
public function actionView($id, $url) {
$product = Product::find()->where(['id'=>$id])->one();
// ...
}