I uploaded my yii2 template advance project in free webhost site...my problem is that I can open my site in the browser like this
how can I remove that frontend/web ?
so that when I'm going to open my frontend in the browser it's just like this
Thank you in advance.
You can try this in your Root/.htaccess
RedirectMatch 301 ^/yiiproj/?$ http://mysite.freehost.com/yiiproj/frontend/web/
if RedirectMatch doesn't help then try the following.
RewriteEngine on
RewriteRule ^yiiproj/?$ http://mysite.freehost.com/yiiproj/frontend/web/ [R=301,NC,L]
You need to put all the framework part outside the web 'downloadable' folders. On any free hosting , you find the downloadable part in the 'public_html' or the 'www' folder.
Basic App
On the root outside the www part, make a folder (eg name it myyiiapp) and put all your app files there.
Move the /web content to the folder www/yiiproj which is the downloadable directory.
Update the web/index.php (which is now at www/yiiproj/index.php) file to point to the correct relative directory of yii application and you should be good to go. You will need to edit the following 3 lines to something like this for basic app.
require(__DIR__ . '/../myyiiapp/vendor/autoload.php');
require(__DIR__ . '/../myyiiapp/vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/../myyiiapp/config/web.php');
Advanced App
In case if you are using Yii advanced app, frontend and backend can be moved separately without keeping the relevant path.
Update both the web/index.php files to point to the correct relevant paths .All the following 8 lines should be updated accordingly in the config files
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/bootstrap.php');
require(__DIR__ . '/../config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/main.php'),
require(__DIR__ . '/../../common/config/main-local.php'),
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
The Philosophy
This is the best / intended approach for yii apps as it protects any kind of remote access to source code and all the public content is already in the /web part which is safe for downloading.
Yii2 is very decoupled , you can make a custom app , have maybe 10 web directories in publicly accessible area. Each web/index.php file pointing to the same vendor dir (as only one yii install is needed), same config files (if you only need different html) or personalized config files(if app has same db but different sets of controllers usually)