Yii2 Advance Application在前端和后端删除'/ web'和'index.php'

时间:2016-02-25 11:04:33

标签: yii2 yii2-advanced-app

我参考了下面给出的链接

Yii2 htaccess - How to hide frontend/web and backend/web COMPLETELY

Remove index.php from url after removing web folder from frontend and backend in yii2

但是,我没有得到输出

显示在以下网址

本地主机/ yii2advance /后端/网络/的index.php?R =站点%2Flogin

本地主机/ yii2advance /前端/网络/的index.php?R =站点%2Flogin

在上面的网址中我删除了/web/index.phpfrontend

中的backend

我得到的网址

本地主机/ yii2advance /后端/站点/登录

本地主机/ yii2advance /前端/站点/登录

2 个答案:

答案 0 :(得分:7)

1-将此代码放在yii2advance文件夹中的.htaccess flie中(项目的主文件夹)

# prevent directory listings
Options -Indexes
IndexIgnore */*

# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^admin(/.+)?$ backend/web/$1 [L,PT]
RewriteRule ^(.+)?$ frontend/web/$1

以上代码转换

  

'本地主机/ yii2advance /前端/网络/ index.php的'

  

'本地主机/ yii2advance /'

并转换

  

'本地主机/ yii2advance /后端/网络/ index.php的'

  

'本地主机/ yii2advance /管理'

2-将此代码添加到frontend / .htaccess和backend / .htaccess文件中:

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

3-在backend / config / main.php中输入以下代码:

'homeUrl' => '/yii2advance/admin',
'request' => [
        'baseUrl' => '/yii2advance/admin', // localhost/yii2advance/admin
    ],
'components' => [
    'urlManager' => [
         'enablePrettyUrl' => true,
         'showScriptName' => false,
         'rules' => [
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            ],
],

4-在frontend / config / main.php中输入以下代码:

'homeUrl' => '/yii2advance',
'request' => [
        'baseUrl' => '/yii2advance', // localhost/yii2advance
    ],
'components' => [
    'urlManager' => [
         'enablePrettyUrl' => true,
         'showScriptName' => false,
         'rules' => [
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            ],
],

答案 1 :(得分:-1)

在“网络”目录中使用以下命令创建“ .htaccess”文件:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

我的pull request已被接受。它将是2.0.19版本。