ilopx/yii2-basic-htaccess

在 webroot 中设置网站目录

1.0 2015-08-22 22:21 UTC

This package is not auto-updated.

Last update: 2024-10-02 10:43:31 UTC


README

#Yii2基本htaccess

Demo

视频演示

Video Demo

a. 自动设置 index.php

此方法自动创建 .htaccess 文件并自动清除。

  • 下载文件 index.php 或 composer require ilopx/yii2-basic-htaccess
  • 放置到yii2应用的根目录
  • 启动 http://{your_yii2_webapp}
  • 按照手动设置中的第3步进行操作

b. 手动设置

1. 步骤

创建文件 {root}/.htaccess

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
</IfModule>
 
<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_URI} ^/.*
    RewriteRule ^(.*)$ web/$1 [L]

    RewriteCond %{REQUEST_URI} !^/web/
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ web/index.php
</IfModule> 

2. 步骤

创建文件 {root}/web/.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

3. 步骤

更新文件 {root}/config/web.php

'request' => [
    'baseUrl' => '',
],
'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
        '' => 'site/index',
        '<action>'=>'site/<action>',
    ],
],