lilbiscuit
lilbiscuit

Reputation: 2249

Yii2 get app web url without index.php

My Yii2 app is located at:

http://www.example.com/myYiiApp/

I want to get that URL from anywhere in my app. But using this:

Url::home(true)

Returns

http://www.example.com/myYiiApp/index.php

Is there are Yii command to return the url without index.php?

Upvotes: 0

Views: 340

Answers (2)

lilbiscuit
lilbiscuit

Reputation: 2249

Barring a Yii direct command, I will use dirname(Url::home(true))

Upvotes: 0

Fabrizio Caldarelli
Fabrizio Caldarelli

Reputation: 3008

Have you tried to configure 'urlManager' in 'components' in config/main.php

'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
],

Take care that .htaccess is configured in web folder:

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

Upvotes: 1

Related Questions