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]



is not working with

'showScriptName' => false



is working with

'showScriptName' => true

Here are my config:


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


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


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: