ilopx/yii2-basic-htaccess

Set web directory in webroot

1.0 2015-08-22 22:21 UTC

This package is not auto-updated.

Last update: 2024-04-17 08:40:19 UTC


README

#Yii2 basic htaccess

Demo

Video Demo

Video Demo

a. Automatic setting index.php

This method created .htaccess files automatically and clear self.

b. Manual setting

1. step

create file {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. step

create file {root}/web/.htaccess:

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

3. step

update file {root}/config/web.php:

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