Module 如何为Yii 2中模块的友好url创建自定义规则
我在前端有一个模块,我想创建一个友好的url,如:Module 如何为Yii 2中模块的友好url创建自定义规则,module,routes,yii2,friendly-url,Module,Routes,Yii2,Friendly Url,我在前端有一个模块,我想创建一个友好的url,如: //yourdomain/a-zA-Z_module-controller-action-id-page-1.html 比如像这样的链接: http://kudufood.com/com-van-phong-lam-the-nao-de-nau-canh-bong-cai-duoc-ngon-kudu_cookbooks_1429067720.html 您可以通过在config/web.php中向应用程序组件添加以下代码并在“规则”中配置自
//yourdomain/a-zA-Z_module-controller-action-id-page-1.html
比如像这样的链接:
http://kudufood.com/com-van-phong-lam-the-nao-de-nau-canh-bong-cai-duoc-ngon-kudu_cookbooks_1429067720.html
您可以通过在config/web.php中向应用程序组件添加以下代码并在“规则”中配置自定义URL来启用漂亮的URL:
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName'=>true,
'rules' => [
// your rules go here
'customURL'=>'my-controller/my-action'
],
如果还希望隐藏index.php,请设置:
'showScriptName'=>false
并在您的/web目录中创建一个.htaccess文件,其中包含以下内容:
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
文档:到目前为止您做了哪些工作?你能发布你的代码吗?我的问题是不能在控制器中创建友好的url。我想对模块做一个友好的介绍。另一件事是:我不想要正斜杠“/”。我想这样:h.t.t.p://yourdomain/a-zA-Z_module-controller-action-id-page-1/