Magento – Magento intermittently caching incorrect base URL

base-urlcacheurl

Every few hours my live Magento 1.7.0.2 installation is caching the wrong link URLs for the category navigation menu.

Sometimes they use the wrong form of the domain (without the www and adding an SID get var) in which case users get endlessly redirected to the homepage or, worse, they sometimes redirect to http://localhost! The same problem also occurs when accessing the backend. Clearing the cache resolves the issue temporarily but it normally resurfaces after a 1-2 hours. Disabling the cache is a temporary fix but obviously not ideal for a production environment.

I’ve never seen this before, any suggestions?

Thanks in advance

Best Answer

Are you using {{base_url}} as your site url in your configuration? If so, that means that users can access the site on any URL that your webserver's configured to use for that vhost. If someone happens to hit the site on localhost at the point when the cache is regenerated, that could be cached.

This is in System -> Configuration -> Web - you should always set the Base URLs explicitly to a real URL (and don't forget the final / on the URLs)

This is a security issue if you are the default vhost on your server too - see Why is using {{base_url}} in a production server not recommended?

Related Topic