Yii2 on subdomain

Hi everyone,

I’ve created an A record in DNS. This is how my path to the app looks like:


And something went wrong with links. Here’s how my frontend/config/main.php looks like:

  'request' => [

        'baseUrl' => '/',


  'urlManager' => [

      'enablePrettyUrl' => true,

      'showScriptName' => false,

      'suffix' => '/',

      'rules' => [

          '' => 'site',

          'logout' => 'site/logout',



This is how I format my links:

<a href="<?php echo Url::to(['user/index']); ?>">Users</a>

On my local machine everything is perfect, but on production, it’s not. I think it’s a problem because I use a subdomain.

Do you know what might be a problem?


Ok. I’ve found that the issue is related to rules.

When I add the next piece of code:

"http://app.example.com/<controller:\w+>/<action:\w+>" => '<controller>/<action>',

The problem is URL output is something like this:


How can I remove one slash? Also,I haven’t tested with parameters.

to remove slash, change suffix.

Hehe, not really. I’ve tried almost everything. It doesn’t work.

If I add ‘.html’ as a suffix my links will be as


Slash is still there. The suffix is actually about the last character(s).

Thanks anyway.



ok, with suffix you removed the last /.

Now, you can try using this much in your rules.

'<controller:\w+>/<action:\w+>" => '<controller>/<action>',

Still if you have problem, you can retain your rules and make baseUrl ‘’ instead of ‘/’.

This rule does not work.

However, I’ve removed baseUrl but links now have /frontend/web/ which is not acceptable.

Okay, I’ve found the solution – for those folks who host their app on the subdomain:

You need to have:

'request' => [

        'baseUrl' => '',


'urlManager' => [

	'enablePrettyUrl' => true,

	'showScriptName' => false,

	'suffix' => '/',

	'baseUrl' => '/', 


Plus you need to have .htaccess in your /frontend/web/ (I had this before I’ve found the problem):

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule . index.php

and in your root folder:

Options -Indexes

<IfModule mod_rewrite.c> 

  RewriteEngine on

  RewriteCond %{REQUEST_URI} !^public

  RewriteRule ^admin/(.*)$ backend/web/$1 [L] 

  RewriteRule ^(.*)$ frontend/web/$1 [L]   



# Deny accessing below extensions

<Files ~ "(.json|.lock|.git)">

Order allow,deny

Deny from all


# Deny accessing dot files

RewriteRule (^\.|/\.) - [F]

# Upload limits

php_value post_max_size 100M

php_value upload_max_filesize 100M

Good luck to everyone!

Perfect!!! thanks a lot it works!!!