Problem with subfolder installs and the MediaManager generating incorrect URLs in places
Reported via email, reproduced here for visibility.
I have installed the WinterCMS 1.2.3 version on one of my testing servers with PHP 8.0 and Mysql 5.7. The installation went smoothly and works very well except for the following thing. When I upload any image in the media section, The URL omits the subdirectory path and redirects to the root path which results in a 404 error for the image. (please refer the video attached)
https://github.com/wintercms/winter/assets/7253840/c89590c0-a57d-456d-93a8-3787e851e2ee
Have you tried this test on previous versions? The official recommendation when installing Winter in subfolders is to set config/cms.php -> linkPolicy to force. Is this issue new to v1.2.3?
This issue has been there in previous version (1.2.2) as well. Also setting linkPolicy to force in config/cms.php generates the preview of the image However if we click on the link of the image it still throws "404 Not Found" error. Please refer to the image attached. You can check the image url on the bottom left side where it skips the subdirectory path.
I've attempted to replicate this, and found that while the scenario as described does happen, it might be the result of the config being cached that it initially shows the wrong public URL for the "Click here" link.
- I set up Winter in a subdirectory. With
cms.linkPolicyset to the default (detect), the media item preview did not show up and the "Click here" link was missing the subdirectory, as described. - By setting
app.urlto the correct URL and settingcms.linkPolicytoforce, the media item preview started displaying correctly, but the "Click here" link was still missing the subdirectory, as described. - Once clearing the cache with
php artisan cache:clear(or giving it about 5-10 minutes for the config cache to invalidate), the "Click here" link started showing the correct URL with the subdirectory being included in the URL.
@bennothommo is this something that the Web Installer could detect and configure for the user (or at least provide an option)?
I can't recall if I've asked this prior, but is there any reason we don't set cms.linkPolicy to force by default? I would argue that if we're providing people the ability to define an app URL, the expectation would be that all links should follow the app URL (like defining WP_HOME and WP_SITEURL for WordPress). The only case it should be detected is if the developer knows that more than one URL to the app might be used (eg. multi-sites).
If this were something we considered changing, then there wouldn't need to be an option in the installer.
@bennothommo I'm not sure, I wouldn't want to change the default in the code, but we could potentially change the default in the config.
It was first introduced in https://github.com/wintercms/winter/commit/9e500985ff776543e4357e044da1cf0c4c5ce859 and switched to detect in https://github.com/wintercms/winter/commit/47eff923e5b8a7a90bb931fac40628938ff16678. Not really any useful information in either of those commits.
I feel like the main reason against changing it at this point is to avoid having to deal with the inevitable support issues from the people not correctly configuring their app.url values.
This issue will be closed and archived in 3 days, as there has been no activity in this issue for the last 6 months. If this issue is still relevant or you would like to see it actioned, please respond within 3 days. If this issue is critical for your business, please reach out to us at [email protected].