EnablePrettyUrl is not working

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?

Guide > Shared Hosting Environment

(http://www.yiiframework.com/doc-2.0/guide-tutorial-shared-hosting.html)

So, I think you’d better not try to change the standard webroot by using .htaccess. Change your webroot name, instead.

P.S.

Do you have 2 .htaccess files? The 2nd one in your post might not take effect if the hosting service enforces you to use the 1st one.

You can also try this alternative, which is the basic app template but with webroot in project root: