1

I have some images in my home page and from time to time the URL of these images get changed somehow and a subdomain is appended to it automatically.

For example: www.mysite.com/sites/default/files/image.png becomes abc.mysite.com/sites/default/files/image.png.

Here are some other facts that might have something to do with this issue:

  • The site supports two languages (english and arabic which is the default language) and this issue only appears in English Site.

  • We had a very old drupal 6 site before that was using Subdomains extensively (using the subdomain module) and I noticed that any subdomain appended to the image url is usually a randomly selected one of these old subdomains. So these domains used to exist. But the weirdest thing is that we actually moved to a completely new server a year ago and we created this new site from scratch using Drupal 7. We have not imported any content or modules from the old site and we don't use subdomains any longer. The old server is no longer active. Also we have removed all subdomains from DNS in cPanel.

  • The issue goes away sometimes after clearing the cache.

What could be causing this weird issue?

  • I noticed that any subdomain appended to the image url is usually a randomly selected one of these old subdomains - we're having this issue with almost random urls: qwww.mydomain.com, w3ww.mydomain.com, www.ddd.mydomain.com, www.eee.mydomain.com. I'm adding this comment to make this question score higher in google search results for such funny subdomains :-) – commonpike Oct 7 '15 at 15:45
2

This is rather big guess, but I think you have everything configured so that your virtual host is responding to all subdomains for your primary domain. In Apache terms this would be something like

ServerName mysite.com
ServerAlais *.mysite.com

And, you have old links that are getting crawled from the old subdomains, and the net result are some bad URLs are being cached.

My suggestion would be to add something like this to your .htaccess

RewriteCond %{HTTP_HOST} !www\.mysite\.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

Make sure this goes right after the RewriteEngine on in the stock Drupal version. I don't think the two example rules in the file will work, as they assume just adding/removing the www and don't take subdomains into account (though I am not 100% sure about this; I haven't looked at these closely in a while). Make sure you clear Drupal cache, too.

Also make sure you back up the file after you change it, so you have the additions the next time you upgrade core.

  • I had a similar case just the other day when I was working on some stuff on my laptop via localhost:.../foo.jpg and then accessing it from my iPhone via 192.../foo.jpg to test it and images weren't showing up because the localhost:.../foo.jpg was being cached, so definitely look and see if any of your users are accessing your site via one of those older domains, or something else is, as @MPD mentioned, crawling through and priming your cache with the old urls. – Jimajamma Dec 30 '12 at 23:19
  • Your answer makes a lot of sense, MPD. We do have *.mysite.com rule in the DNS configuration in CPanel. We did it because we wanted users to be redirected to our site main home page if they access the site using one of the old subdomains. So what does the htaccess rules you suggested do exactly??? – Ahmed Jabar Dec 31 '12 at 6:08
  • The DNS wildcard in cPanel just maps all requests for that domain to the same directory on the server; it doesn't do any redirection. The .htaccess rules will do the redirects before Drupal handles everything. Drupal and the end user will only see www.mysite.com for everything. Try out it out manually by going to whatever.mysite.com, before and after you put the .htaccess rules in place. – mpdonadio Dec 31 '12 at 15:41
  • This answer doesn't necessarily address the problem directly. Drupal shouldn't be dishing out these URLs in the first place. Why aren't they consistently the same domain? – Hawkee Oct 4 '13 at 15:32
  • @Hawkee, the post says you have old links that are getting crawled from the old subdomains, and the net result are some bad URLs are being cached. So a combination of dumb bots and cache. – commonpike Nov 8 '15 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.