Skip to content

Instantly share code, notes, and snippets.

@haifahrul
Last active April 9, 2020 16:18
Show Gist options
  • Save haifahrul/daf35f934eb62f0ea941fe699c79dde1 to your computer and use it in GitHub Desktop.
Save haifahrul/daf35f934eb62f0ea941fe699c79dde1 to your computer and use it in GitHub Desktop.
Yii2 Basic Web for Hosting - Add code below into your root projects
<?php
file_put_contents('.htaccess', <<<END
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
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>
END
);
if (!is_dir('web')){
mkdir('web');
}
file_put_contents('web/.htaccess', <<<END
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
END
);
unlink(__FILE__);
header("Location: " . "http://" . $_SERVER['HTTP_HOST']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment