The YII2 basic app is installed under localhost in ‘ims’ folder.The links are like
http://192.168.0.99/ims/web/ (homepage)
http://192.168.0.99/ims/web/index.php?r=site%2Fabout (about us page)
So far what i have done is.
1) in web/.htaccess file
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
2) in root .htaccess
Options -Indexes
RewriteEngine on
RewriteRule ^(.*)$ web/$1 [L]
3) In config/web.php
'components' => [
'urlManager' => [
'class' => 'yiiwebUrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'baseUrl' => '/',
],
This fixes the following things:
1) Links are SEO friendly now
2) index.php does not show now in url
3) The homepage can be accessed with http://192.168.0.99/ims/
Issue:-
The about , contact & login links now change to
http://192.168.0.99/site/about
http://192.168.0.99/site/contact
http://192.168.0.99/site/login
It misses the base folder name in the url ‘ims’. Any suggestions or ideas regarding this ?
Note:- I do not wish to use the Apache configuration to achieve this and also i do not wish to move the contents of web folder outside.
I wish to hide the ‘web’ from the url without changing the structure of the YII2 basic application.
3
Answers
I am answering my own question here :-
the only change that i needed to make it work to
So the changed code looks like
Now i can browse all the pages without text 'web' in it. And this is achieved without making any apache configurations or moving the web folder in the root. :)
So far this worked for me finally
1. In web/.htaccess file
2. Then in root .htaccess
3. In config/web.php
NB: Just remove the ‘baseUrl’=>’/’ in the config/web.php