homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Htaccess rewrite rule not working
subdomain rewrite to root folder

 8:31 am on Jan 31, 2012 (gmt 0)

I need [img.example.com...]
to rewrite to http://www.example.com/images/buttons/viewpost.gif

I have:

RewriteCond %{HTTP_HOST} ^img.example.com.com$
RewriteRule ^(.*)$ http://www.example.com/images/$1 [R=301,L]

But it doesn't seem to be working. Can someone good with htaccess please help.



 8:35 am on Jan 31, 2012 (gmt 0)

Your code above is for an external redirect not an internal rewite.

Which one do you actually want? Redirects and rewrites are very different things even though both can be done with a RewriteRule.

What URL should the user be requesting? After they request it, should the browser address bar then change to a different URL?


 9:22 am on Jan 31, 2012 (gmt 0)

:: cough, cough ::


Anyway, it's a gif. Why do you need to rewrite at all? Yes, there are situations where you would rewrite a gif. I've done it myself. But I don't see it here.


 1:25 pm on Jan 31, 2012 (gmt 0)

The user would have the image embedded in the html

img.example.com was actually an aws cloud resource but we need to move away from it now.

So the url needs to be redirected to - www.example.com/images//buttons/viewpost.gif

The .com.com was a typo which happened while I was copying the htaccess here and removing the domain name. :)


 9:11 pm on Jan 31, 2012 (gmt 0)

Yeah, that's what I meant. Why can't you simply change the html? Is it a page that a lot of people have saved locally?

Always constrain your RewriteRule as tightly as possible so mod_rewrite doesn't need to check the conditions for every single request. If the filename is


put that part into the "pattern" side of the Rule itself. And then have the Condition check that the host is not what you want it to be.

Since it's an image within html, you can use either a rewrite or a redirect. But a redirect is safer. And, again, you only need to pick up the ones that aren't already getting the correct URL from the html itself.


 7:03 am on Feb 1, 2012 (gmt 0)

I guess we may need to keep the aws on - you are right - it doesn't make sense to check and rewrite on every page load - a redirect would've worked cause then it would've been only when the image appeared in the html.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved