1. <i id='KcO6g'><tr id='KcO6g'><dt id='KcO6g'><q id='KcO6g'><span id='KcO6g'><b id='KcO6g'><form id='KcO6g'><ins id='KcO6g'></ins><ul id='KcO6g'></ul><sub id='KcO6g'></sub></form><legend id='KcO6g'></legend><bdo id='KcO6g'><pre id='KcO6g'><center id='KcO6g'></center></pre></bdo></b><th id='KcO6g'></th></span></q></dt></tr></i><div id='KcO6g'><tfoot id='KcO6g'></tfoot><dl id='KcO6g'><fieldset id='KcO6g'></fieldset></dl></div>

    2. <small id='KcO6g'></small><noframes id='KcO6g'>

    3. <legend id='KcO6g'><style id='KcO6g'><dir id='KcO6g'><q id='KcO6g'></q></dir></style></legend>

    4. <tfoot id='KcO6g'></tfoot>
        <bdo id='KcO6g'></bdo><ul id='KcO6g'></ul>

        如何删除 url (/web/index.php) yii 2 并使用干净的 url 参数设置路由?

        时间:2023-10-16

            <tbody id='Y9I7n'></tbody>
          • <small id='Y9I7n'></small><noframes id='Y9I7n'>

              <bdo id='Y9I7n'></bdo><ul id='Y9I7n'></ul>
              <tfoot id='Y9I7n'></tfoot>
              <i id='Y9I7n'><tr id='Y9I7n'><dt id='Y9I7n'><q id='Y9I7n'><span id='Y9I7n'><b id='Y9I7n'><form id='Y9I7n'><ins id='Y9I7n'></ins><ul id='Y9I7n'></ul><sub id='Y9I7n'></sub></form><legend id='Y9I7n'></legend><bdo id='Y9I7n'><pre id='Y9I7n'><center id='Y9I7n'></center></pre></bdo></b><th id='Y9I7n'></th></span></q></dt></tr></i><div id='Y9I7n'><tfoot id='Y9I7n'></tfoot><dl id='Y9I7n'><fieldset id='Y9I7n'></fieldset></dl></div>

                  <legend id='Y9I7n'><style id='Y9I7n'><dir id='Y9I7n'><q id='Y9I7n'></q></dir></style></legend>
                  本文介绍了如何删除 url (/web/index.php) yii 2 并使用干净的 url 参数设置路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  第一个问题:我已经删除了 index.php,但我也想删除 /web.这是我的 .htaccess

                  RewriteEngine on# 如果目录或文件存在,直接使用RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d# 否则将其转发到 index.php重写规则.索引.php

                  这是config/web.php

                  'urlManager' =>['类' =>'yiiwebUrlManager',//禁用 index.php'showScriptName' =>错误的,//禁用 r= 路由'enablePrettyUrl' =>真的,'规则' =>大批('<控制器:w+>/'=>'<控制器>/视图','<控制器:w+>/<动作:w+>/<id:d+>'=>'<控制器>/<动作>','<控制器:w+>/<动作:w+>'=>'<控制器>/<动作>',),],

                  它工作正常,但仍在使用 /web .是否可以删除 /web ?

                  第二个问题:

                  我不能用那个干净的 url 参数设置路由,我的路由 Url::toRoute(['transaction/getrequestdetail/', 'id' => 1 ]);

                  路线应该如何?以及如何使用 2 个参数路由?

                  解决方案

                  对于高级应用,请按照以下步骤操作:

                  1) 将以下 htaccess 添加到 frontend/web

                  RewriteEngine on# 如果目录或文件存在,直接使用请求RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d# 否则将请求转发到 index.php重写规则.索引.php

                  2) 将以下 htaccess 添加到安装应用程序的根文件夹

                  # 防止目录列表选项 - 索引索引忽略 */*# 跟随符号链接选项 FollowSymlinks重写引擎开启RewriteRule ^admin(/.+)?$ backend/web/$1 [L,PT]RewriteRule ^(.+)?$ frontend/web/$1

                  3) 使用顶部的以下内容编辑您的 frontend/config/main.php 文件

                  使用yiiwebRequest;$baseUrl = str_replace('/frontend/web', '', (new Request)->getBaseUrl());

                  4) 将 request component 添加到同一个文件中的 components 数组,即 frontend/config/main.php

                  'components' =>['请求' =>['baseUrl' =>$baseUrl,],],

                  就是这样.现在你可以在没有 web/index.php 的情况下访问前端

                  对于第二个问题,您需要在 URL 管理器组件中为其编写规则.

                  像这样:

                  'urlManager' =>['baseUrl' =>$baseUrl,'类' =>'yiiwebUrlManager',//禁用 index.php'showScriptName' =>错误的,//禁用 r= 路由'enablePrettyUrl' =>真的,'规则' =>大批('交易/getrequestdetail/'=>'交易/获取请求详细信息',),],

                  first question: i already remove index.php, but i want remove /web also. this is my .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
                  

                  and this is config/web.php

                  'urlManager' => [
                              'class' => 'yiiwebUrlManager',
                              // Disable index.php
                              'showScriptName' => false,
                              // Disable r= routes
                              'enablePrettyUrl' => true,
                              'rules' => array(
                                      '<controller:w+>/<id:d+>' => '<controller>/view',
                                      '<controller:w+>/<action:w+>/<id:d+>' => '<controller>/<action>',
                                      '<controller:w+>/<action:w+>' => '<controller>/<action>',
                              ),
                          ],
                  

                  it's working fine, but it's still using /web . is it possible remove /web ?

                  second question:

                  i can't set route with parameter with that clean url, my route Url::toRoute(['transaction/getrequestdetail/', 'id' => 1 ]);

                  how the route should be ? and how with 2 parameter route ?

                  解决方案

                  For advanced application follow these steps:

                  1) Add the following htaccess to frontend/web

                  RewriteEngine on
                  
                  # If a directory or a file exists, use the request directly
                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteCond %{REQUEST_FILENAME} !-d
                  # Otherwise forward the request to index.php
                  RewriteRule . index.php
                  

                  2) Add the following htaccess to root folder where application is installed

                  # prevent directory listings
                  Options -Indexes
                  IndexIgnore */*
                  
                  # follow symbolic links
                  Options FollowSymlinks
                  RewriteEngine on
                  RewriteRule ^admin(/.+)?$ backend/web/$1 [L,PT]
                  RewriteRule ^(.+)?$ frontend/web/$1
                  

                  3) Edit your frontend/config/main.php file with the following at the top

                  use yiiwebRequest;
                  $baseUrl = str_replace('/frontend/web', '', (new Request)->getBaseUrl());
                  

                  4) Add the request component to the components array in the same file i.e frontend/config/main.php

                  'components' => [
                          'request' => [
                              'baseUrl' => $baseUrl,
                          ],
                  ],
                  

                  That's it.Now you can access the frontend without web/index.php

                  For you second question you need to write the rule for it in your URL manager component.

                  Something like this:

                  'urlManager' => [
                              'baseUrl' => $baseUrl,
                              'class' => 'yiiwebUrlManager',
                              // Disable index.php
                              'showScriptName' => false,
                              // Disable r= routes
                              'enablePrettyUrl' => true,
                              'rules' => array(
                                      'transaction/getrequestdetail/<id>' => 'transaction/getrequestdetail',
                             ),
                  ],
                  

                  这篇关于如何删除 url (/web/index.php) yii 2 并使用干净的 url 参数设置路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:YII2:添加动态表单字段及其验证 下一篇:Yii2 动态 URL 路由规则

                  相关文章

                  <tfoot id='uyMwI'></tfoot>
                • <legend id='uyMwI'><style id='uyMwI'><dir id='uyMwI'><q id='uyMwI'></q></dir></style></legend>

                  • <bdo id='uyMwI'></bdo><ul id='uyMwI'></ul>

                  1. <small id='uyMwI'></small><noframes id='uyMwI'>

                    <i id='uyMwI'><tr id='uyMwI'><dt id='uyMwI'><q id='uyMwI'><span id='uyMwI'><b id='uyMwI'><form id='uyMwI'><ins id='uyMwI'></ins><ul id='uyMwI'></ul><sub id='uyMwI'></sub></form><legend id='uyMwI'></legend><bdo id='uyMwI'><pre id='uyMwI'><center id='uyMwI'></center></pre></bdo></b><th id='uyMwI'></th></span></q></dt></tr></i><div id='uyMwI'><tfoot id='uyMwI'></tfoot><dl id='uyMwI'><fieldset id='uyMwI'></fieldset></dl></div>