yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

Duplication path in baseUrl #18618

Closed blink2004 closed 3 years ago

blink2004 commented 3 years ago

Didn't work $config['components']['request']['baseUrl'] in Basic template.

What steps will reproduce the problem?

  1. Create Yii2 site in subdomain. For example, http://domain/subdomain1/subdomain2/web/
  2. Set value $config['components']['request']['baseUrl'] in file config/web.php to "" (empty string).
  3. Open main page again. You can see that assets files was didn't find and them paths looks like http://domain/assets/...

Next case.

  1. Create Yii2 site in subdomain. For example, http://domain/subdomain1/subdomain2/web/
  2. Set value $config['components']['request']['baseUrl'] in file config/web.php to "subdomain1/subdomain2".
  3. Open main page again. You can see that assets files was didn't find and them paths are http://domain/subdomain1/subdomain2/subdomain1/subdomain2/assets/...

Paths are duplicated.

What is the expected result?

No duplication.

What do you get instead?

Additional info

Q A
Yii version 2.0.41
PHP version PHP 7.4.3
Operating system 5.8.0-50-generic #56~20.04.1-Ubuntu SMP Mon Apr 12 21:46:35 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
bizley commented 3 years ago

Does it work if you set it to /subdomain1/subdomain2?

blink2004 commented 3 years ago

Does it work if you set it to /subdomain1/subdomain2?

Yes, it's works. Thanks. But I didn't find this information in https://www.yiiframework.com/doc/api/2.0/yii-web-request#$baseUrl-detail

bizley commented 3 years ago

Well, it says "relative URL". Could you suggest something less confusing? We can update it.

blink2004 commented 3 years ago

This is opened for discussion. I'm not sure that my point of view make documentation better insted of worse. For my opinion I would describe by template:

  1. Property name
  2. Simple description
  3. Value by default
  4. Full description with examples. Possible with few cases. It would give me confidence when writing code.

For example: $baseUrl - relative URL from server name for files (such as .js, .css, images, etc). Value by default is null. Empty ("") value sets path from server name. All paths between it and files will be ignored. All values should started from slash ("/"). If not make this the path will be duplicated. Not correct: project/folder Correct: /project/folder etc.

But I don't know all possible cases and afraid to make description worse instead of make better.

bizley commented 3 years ago

I'm biased here and for me it would be overkill, not to mention that if we would do that for the whole documentation the project size would be 10x larger. Anyway, I will mention the leading slash in the docs.