Fixed It: Magento Base URL Changes Did Not Reflect on the Frontend.
Arriving at the office this morning, I learned that as I camped in my daughters fort last night, our AWS CloudFront CDN started throwing 502 errors. Not a big deal right? Just log into the backend, change the base URLs for our static assets, and clear the cache. Of course, it’s going to require more than that.
Step 2: Using my handy dandy magerun helper, I quickly updated the CDN URIs.
$ magerun mysql
$ mysql >
SELECT DATABASE();/* Just a bit of reassurance that magerun placed us in the right database */
$ mysql > update core_config_data set value='https://www.domain.com/js/' where value='https://cdn.domain.com/js/';
$ mysql > update core_config_data set value='https://www.domain.com/skin/' where value='https://cdn.domain.com/skin/';
$ mysql > update core_config_data set value='https://www.domain.com/media/' where value='https://cdn.domain.com/media/';
$ mysql > exit;
$ magerun cache:flush
Step 3: It appears that some of the assets are being referenced by merged CSS, let’s turn that off:
$ magerun dev:merge-css --global
/* Heck, we're trouble shooting, so unmerge JS as well */
$ magerun dev:merge-js --global
Alright, we’ve made some progress! My homepage is rendering normally on desktop, however, there are a few more media paths in the Google Console that are still pointing to our CDN.
Step 4: Locate the last of rogue paths. I want to make quick work of this, so, let’s search via the console for template files with hard-coded paths:
$ grep -r --include *.phtml 'cdn' ./
No, results? Damn I’m good with my template paths. Maybe they’re living in my site sliders, CMS blocks, or CMS pages? Let’s check.
# Our main CMS content is contained within a slider module, CMS Blocks and CMS Pages.
$ magerun mysql
$ mysql > select page_id from cms_page where content like "%cdn.domain.com%";
$ mysql > select block_id from cms_block where content like "%cdn.domain.com%";
# And our Slider Module - you'll need to consider where your content lives
$ mysql > select slider_id from auguria_sliders where cms_content like "%cdn.domain.com%";
And here it all is. These queries returned a number of results letting me know where my CDN path was hard-coded. Shame on me, I know.
You’ve updated your base URLs in Magento but still do not see the changes reflected in the UI. Consider the following:
- Disable merged CSS and JS. You could clear the cache, but you’re trouble shooting, just disable it as well.
- Search your template files for your hard-coded CDN URL. The grep command within terminal makes this quick and painless.
- Search your database, namely your cms_block and cms_page tables, for your hard-coded CDN URL. You know which other extensions you may be using to manage content (such as sliders), so check their DB tables as well.