yii2美化url(你的虚拟域名/site/index)

121 阅读1分钟

第一步:xampp在的根目录:
请添加图片描述复制粘贴:下面的

# prevent directory listings
Options -Indexes
# follow symbolic links
Options FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/admin/$
RewriteRule ^(admin)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT]

RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /frontend/web/$1

第二步:在backend\web里面创建一个.htaccess文件(复制粘贴下来的代码)
请添加图片描述第二步:在frontend\web里面创建一个.htaccess文件(复制粘贴下来的代码)
请添加图片描述

# use mod_rewrite for pretty URL support
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

第三步:frontend\config\main.php文件中复制粘贴下面的代码;就行了
请添加图片描述

 'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules'=>[
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ],
        ]

显示效果:

在这里插入图片描述