Subdomain Images Not Loading properly

Posted on 2012-09-17
Medium Priority
Last Modified: 2012-09-19
I created a subdomain for a website: m.mysite.com
I am using an htaccess file to detect if a visitor is mobile, if yes they are redirected to m.mysite.com if not they go to www.mysite.com

I didn't want to have to upload images to the mobile subdomain, I wanted to call them directly from the main site (www.) using http://www.mysite.com/image

The problem is that the images are loading on my desktop computer  (the links are correct/no broken links), but on my cellphone (and anyone else that has tested it) the images are not loading unless they are either: in the subdomain (without the http request) or called from a different domain altogether. Images called from www.mysite.com will not load on the cellphone.

I called tech support and while they were not able to directly help me, they felt it might be the .htaccess file. They found the same thing. Images loaded on desktops but not on cellphones.

I have very little understanding of this, but is there anything in the following that could be causing the problems?

RewriteEngine on
rewritecond %{http_host} ^mysite.com [nc]
rewriterule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

AddType text/html .shtml .html .htm
AddHandler server-parsed .shtml .html .htm

# Check if this is the noredirect query string
RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]

# Check if this looks like a mobile device
# (You could add another [OR] to the second one and add in what you
#  had to check, but I believe most mobile devices should send at
#  least one of these headers)
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "iPhone|iPad|iPod" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} BlackBerry [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Android [NC,OR]
RewriteCond %{HTTP_USER_AGENT} googlebot-mobile [NC]
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST}          !^m\.
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie}        !\smredir=0(;|$)
# Now redirect to the mobile site
RewriteRule ^ http://m.mysite.com%{REQUEST_URI} [R,L]

ErrorDocument 404 /notfound.html

Any help would be greatly appreciated.
Question by:dresdena1
  • 2

Author Comment

ID: 38410043
As a follow up comment to this question. When I remove the redirect section of the htaccess file the images load on the mobile browser just fine.

LVL 51

Accepted Solution

ahoffmann earned 2000 total points
ID: 38411545
>  RewriteRule ^ http://m.mysite.com%{REQUEST_URI} [R,L]

look strange, can you replace it by

   RewriteRule .* http://m.mysite.com%{REQUEST_URI} [R,L]

also, can you please post the IMG tage which is not loaded (please only that IMG tag and *not* the complete source)

Author Closing Comment

ID: 38416266
Thank you for the response.
While I was waiting, I found http://detectmobilebrowsers.com/ and downloaded the Apache file and it is working correctly.
Thank you again.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question