Hey Yii developers ever wondered how you can get the index.php and the ugly r= from the url. Its simple
You need to do three things.
first thing
'urlManager' =>[
'enablePrettyUrl'=>'true',
'showScriptName'=>'false'
]
The urlManager is a component so add it to the components array that we have in the web.php file if you are using the basic app template.
the 'enablePrettyUrl' => 'true' removes the ugly r= from the url that is simple enough so your site index will be like ' domainname.com/index.php/site/index '
and the 'showScriptName'=>'false' tells yii that we don't want to show the index.php in our urls
second thing
but there is one more thing you need to do that is to add a .htaccess file to your document root. That means inside the web directory below are the things you need to add to the .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?r=$1 [L,QSA]
third thing
Make sure you enable mod rewrite by running the below command in your terminal
domainname.com/site/index
Thats it if you have any issues do comment
You need to do three things.
first thing
'urlManager' =>[
'enablePrettyUrl'=>'true',
'showScriptName'=>'false'
]
The urlManager is a component so add it to the components array that we have in the web.php file if you are using the basic app template.
the 'enablePrettyUrl' => 'true' removes the ugly r= from the url that is simple enough so your site index will be like ' domainname.com/index.php/site/index '
and the 'showScriptName'=>'false' tells yii that we don't want to show the index.php in our urls
second thing
but there is one more thing you need to do that is to add a .htaccess file to your document root. That means inside the web directory below are the things you need to add to the .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?r=$1 [L,QSA]
third thing
Make sure you enable mod rewrite by running the below command in your terminal
a2enmod rewrite
Now you will be able to access site index with the below urldomainname.com/site/index
Thats it if you have any issues do comment
Reference: https://m.youtube.com/user/DoingITeasyChannel
0 Comments