yii2:在使用模块和获取参数时,如何配置Url管理器?
我试图在我的模块中配置Url,但在访问以下Url时遇到404错误。这是我的产品页面url示例:yii2:在使用模块和获取参数时,如何配置Url管理器?,yii2,Yii2,我试图在我的模块中配置Url,但在访问以下Url时遇到404错误。这是我的产品页面url示例: http://localhost/jambomall/web/products/products/details-product?deal_key=nvx3FtQf&url_title=3-Jojo-Cat-ponted-heels 我希望Url管理器显示以下内容: http://localhost/jambomall/web/products/details-product/nvx3FtQ
http://localhost/jambomall/web/products/products/details-product?deal_key=nvx3FtQf&url_title=3-Jojo-Cat-ponted-heels
我希望Url管理器显示以下内容:
http://localhost/jambomall/web/products/details-product/nvx3FtQf/3-Jojo-Cat-ponted-heels
如何配置我的Url管理器以显示此内容?这对我不起作用
'products/<deal_key:\w+>/<url_title:\w+>' => 'products/products/details-products'
在
web.php
文件中添加以下代码
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
并将.htaccess
文件添加到web
文件夹中,以获取以下代码
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
您的.htaccess似乎还可以。请参阅下面的配置。这可能对你有用
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => array(
'' => 'site/index',
'module/<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
'urlManager'=>[
'class'=>'yii\web\UrlManager',
“enablePrettyUrl”=>true,
'showScriptName'=>false,
'规则'=>数组(
''=>'站点/索引',
“模块//”=>“/”,
“/”=>“/视图”,
'//' => '/',
'/' => '/',
),
],
很抱歉,我不太了解这些配置。你能根据我的例子来写你的例子吗?忘记其他的事情,只需添加'module//'=>'/'/',
,看看它是否有效。
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
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => array(
'' => 'site/index',
'module/<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],