I build a small project on Yii2 and it s working fine in Localhost, but not in a Share Hosting.
Because I don’t have access to httpd.conf file, i could only use .htaccess file to set the Web folder as the root folder. So i use this .htacess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
Now
www.example.com/articles/list
is not working with
'showScriptName' => false
But
www.example.com/web/index.php?r=articles/list
is working with
'showScriptName' => true
Here are my config:
.htaccess
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
# Disable Directory Browsing
Options All -Indexes
UrlManager component
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'baseUrl' => '/',
'rules' => [
...
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
],
],
I don’t understand why showScriptName is not working?