diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..449ce51
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+example.png export-ignore
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 70f0875..723ef36 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1 @@
-assets/*
-!assets/.gitignore
-protected/runtime/*
-!protected/runtime/.gitignore
-protected/data/*.db
-themes/classic/views/
+.idea
\ No newline at end of file
diff --git a/README.md b/README.md
index 4065624..04640f4 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,21 @@
#Yii2 basic htaccess
-root/.htaccess:
+
+
+
+## Video Demo
+[](http://www.youtube.com/watch?v=0sxqNaznhlc)
+
+## a. Automatic setting [index.php](https://cdn.rawgit.com/ilopX/yii2-basic-htaccess/master/index.php)
+This method created .htaccess files automatically and clear self.
+
++ Download file [index.php](https://cdn.rawgit.com/ilopX/yii2-basic-htaccess/master/index.php) or composer require ilopx/yii2-basic-htaccess
++ Put to root yii2 application
++ Start http://{your_yii2_webapp}
++ Follow [step 3 in Manual setting](#3-step)
+
+## b. Manual setting
+### 1. step
+#### create file {root}/.htaccess:
```
Options +FollowSymlinks
@@ -8,10 +24,6 @@ root/.htaccess:
RewriteCond %{REQUEST_URI} ^/.*
- #RewriteRule ^assets/(.*)$ /web/assets/$1 [L]
- #RewriteRule ^css/(.*)$ web/css/$1 [L]
- #RewriteRule ^js/(.*)$ web/js/$1 [L]
- #RewriteRule ^images/(.*)$ web/images/$1 [L]
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{REQUEST_URI} !^/web/
@@ -20,15 +32,16 @@ root/.htaccess:
RewriteRule ^.*$ web/index.php
```
-root/web/.htaccess:
+
+### 2. step
+#### create file {root}/web/.htaccess:
```
-# Если это папка или файл, открываем его
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
-# В противном случае перенаправляем на index.php
RewriteRule . index.php
```
-root/config/web.php:
+### 3. step
+#### update file {root}/config/web.php:
```php
'request' => [
'baseUrl' => '',
@@ -41,8 +54,4 @@ root/config/web.php:
''=>'site/',
],
],
-'assetManager' => [
- 'basePath' => '@webroot/assets',
- 'baseUrl' => '@web/assets'
-],
```
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..00431ec
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,12 @@
+{
+ "name": "ilopx/yii2-basic-htaccess",
+ "description": "Set web directory in webroot",
+ "minimum-stability": "stable",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "ilopX",
+ "email": "ilopX@ukr.net"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/example.png b/example.png
new file mode 100644
index 0000000..149ecfe
Binary files /dev/null and b/example.png differ
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..da276b8
--- /dev/null
+++ b/index.php
@@ -0,0 +1,33 @@
+
+ Options +SymLinksIfOwnerMatch
+ RewriteEngine On
+
+
+
+ RewriteCond %{REQUEST_URI} ^/.*
+ RewriteRule ^(.*)$ web/$1 [L]
+ RewriteCond %{REQUEST_URI} !^/web/
+ RewriteCond %{REQUEST_FILENAME} !-f [OR]
+ RewriteCond %{REQUEST_FILENAME} !-d
+ RewriteRule ^.*$ web/index.php
+
+END
+);
+
+if (!is_dir('web')){
+ mkdir('web');
+}
+
+file_put_contents('web/.htaccess', << 'basic',
- 'basePath' => dirname(__DIR__),
- 'bootstrap' => ['log'],
- 'components' => [
- 'request' => [
- 'baseUrl' => '',
- 'cookieValidationKey' => 'insert a secret key',
- ],
- 'urlManager' => [
- 'enablePrettyUrl' => true,
- 'showScriptName' => false,
- 'rules' => [
- '' => 'site/index',
- ''=>'site/',
- ],
- ],
- 'assetManager' => [
- 'basePath' => '@webroot/assets',
- 'baseUrl' => '@web/assets'
- ],
- 'cache' => [
- 'class' => 'yii\caching\FileCache',
- ],
- 'user' => [
- 'identityClass' => 'app\models\User',
- 'enableAutoLogin' => true,
- ],
- 'errorHandler' => [
- 'errorAction' => 'site/error',
- ],
- 'mailer' => [
- 'class' => 'yii\swiftmailer\Mailer',
- // send all mails to a file by default. You have to set
- // 'useFileTransport' to false and configure a transport
- // for the mailer to send real emails.
- 'useFileTransport' => true,
- ],
- 'log' => [
- 'traceLevel' => YII_DEBUG ? 3 : 0,
- 'targets' => [
- [
- 'class' => 'yii\log\FileTarget',
- 'levels' => ['error', 'warning'],
- ],
- ],
- ],
- 'db' => require(__DIR__ . '/db.php'),
- ],
- 'params' => $params,
-];
-
-if (YII_ENV_DEV) {
- // configuration adjustments for 'dev' environment
- $config['bootstrap'][] = 'debug';
- $config['modules']['debug'] = 'yii\debug\Module';
-
- $config['bootstrap'][] = 'gii';
- $config['modules']['gii'] = 'yii\gii\Module';
-}
-
-return $config;
diff --git a/test/Util.php b/test/Util.php
new file mode 100644
index 0000000..a743db7
--- /dev/null
+++ b/test/Util.php
@@ -0,0 +1,54 @@
+clear();
+ }
+
+ function clear(){
+ foreach($this->clearFiles as $file){
+ if (file_exists($file))
+ unlink($file);
+ }
+
+ foreach($this->clearFiles as $file){
+ if (is_dir($dir = dirname($file)) && $dir != '.')
+ rmdir($dir);
+ }
+ }
+
+ function runIndexFile(){
+ $fileIndex = dirname(__DIR__).'/index.php';
+ if (file_exists($fileIndex)){
+ copy($fileIndex, 'index.php');
+ $this->msg('run "index.php"');
+ exec('php '.__DIR__.'\index.php');
+ }else{
+ throw new Exception("File \"$fileIndex\"' not exists");
+ }
+ }
+
+ function ok($msg){
+ echo "$msg -> ok\n";
+ }
+
+ function error($msg){
+ throw new Exception($msg);
+ }
+
+ function msg($msg){
+ echo "$msg\n";
+ }
+}
\ No newline at end of file
diff --git a/test/run.php b/test/run.php
new file mode 100644
index 0000000..e6467e9
--- /dev/null
+++ b/test/run.php
@@ -0,0 +1,38 @@
+runIndexFile();
+
+if (file_exists(__DIR__.'\index.php')){
+ $util->error("File \"index.php\" not self clear");
+}else{
+ $util->ok('Self clear "index.php"');
+}
+
+if (!file_exists('.htaccess')){
+ $util->error("File \"\\.htaccess\" not created");
+}
+else{
+ $util->ok("Create file \"\\.htaccess\"");
+}
+
+if (!file_exists('web/.htaccess')){
+ $util->error("File \"\\web\\.htaccess\" not created");
+}
+else{
+ $util->ok("Create file \"\\web\\.htaccess\"");
+}
+
+$util->ok("All");
+
+$util->clear();
+
diff --git a/src/.htaccess b/{root}/.htaccess
similarity index 93%
rename from src/.htaccess
rename to {root}/.htaccess
index 821312b..6cbafe7 100644
--- a/src/.htaccess
+++ b/{root}/.htaccess
@@ -1,5 +1,5 @@
- Options +FollowSymlinks
+ Options +SymLinksIfOwnerMatch
RewriteEngine On
diff --git a/src/web/.htaccess b/{root}/web/.htaccess
similarity index 99%
rename from src/web/.htaccess
rename to {root}/web/.htaccess
index 2db3492..d2e0d92 100644
--- a/src/web/.htaccess
+++ b/{root}/web/.htaccess
@@ -3,3 +3,5 @@ RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# В противном случае перенаправляем на index.php
RewriteRule . index.php
+
+