![]() |
Rewriting image directory for a dynamic subdomain - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Rewriting image directory for a dynamic subdomain (/showthread.php?tid=16310) Pages:
1
2
|
Rewriting image directory for a dynamic subdomain - El Forum - 03-03-2009 [eluser]johncook[/eluser] I'm having htaccess issues. I want to rewrite subdomains so that: http://subdomain.domain.com/ rewrites to http://www.domain.com/page.php I also want to rewrite the subdomain's image directory into a subdirectory in the main images directory. For example: http://subdomain.domain.com/images/pic.jpg rewrites to http://www.domain.com/images/subdomain/pic.jpg To do this, I used the following htaccess code: Code: # rewrite any subdomain non-images to page.php Any html or php pages redirect fine but any jpg or gif files generate an Internal Server Error. Any tips on what I did wrong? Rewriting image directory for a dynamic subdomain - El Forum - 03-03-2009 [eluser]TheFuzzy0ne[/eluser] I'm quite certain it's got something to do with the %1's you've added. I'm pretty sure the first one should be $1, Not too sure about the second one. Rewriting image directory for a dynamic subdomain - El Forum - 03-03-2009 [eluser]johncook[/eluser] The %1 is meant to grab the subdomain from the preceding RewriteCond rule. But even if I leave the %1 out, there's weirdness. I tried rewriting to images/$1 and it works okay. Then I tried manually rewriting to a subdirectory in the images directory. Eg - images/test/$1 and it gave an Internal Server Error. So it almost seems like rewriting to a subdirectory in images is what causes the problem. Not sure why though. Rewriting image directory for a dynamic subdomain - El Forum - 03-03-2009 [eluser]TheFuzzy0ne[/eluser] I'm no expert, but perhaps something like this might work: Code: # rewrite any subdomain non-images to page.php I really need to start reading up on mod_rewrite... Rewriting image directory for a dynamic subdomain - El Forum - 03-03-2009 [eluser]johncook[/eluser] Thanks for the reply. I don't think the error is caused in the RewriteRule ^(.*) page.php?#1. All that does is grab the query string from the original URL and append it to page.php (#1 grabs content from the previous RewriteCond rule). Plus through testing, I've worked out that that RewriteRule is not being applied to images - the "RewriteCond %{REQUEST_URI} !\.(gif|jpg|png)$" condition eliminates images from this rule. But I did try your code just in case - still got the server error. My guess is the rewrite rule "RewriteRule ^images/(.*) images/%1/$1" is causing an infinite loop (eg - subdomain.domain.com/images/pic.jpg is getting written to subdomain.domain.com/images/subdomain/pic.jpg and so on...). But I don't know how to stop that from happening. Rewriting image directory for a dynamic subdomain - El Forum - 03-03-2009 [eluser]TheFuzzy0ne[/eluser] The way to test would be to comment out the last line, and see what happens. Rewriting image directory for a dynamic subdomain - El Forum - 03-03-2009 [eluser]johncook[/eluser] That's the weird thing. If I comment out the last line, it now rewrites any subdomain image into the main image directory. Eg - subdomain.domain.com/images/pic.jpg >>> www.domain.com/images/pic.jpg But I don't have any rewrite rule that would do that. I don't get how that happens. Rewriting image directory for a dynamic subdomain - El Forum - 03-03-2009 [eluser]TheFuzzy0ne[/eluser] That's covered by the first rule. If the file extension is gif, jpg or png, the request is not routed to the index.php (via CodeIgniter). Rewriting image directory for a dynamic subdomain - El Forum - 03-03-2009 [eluser]johncook[/eluser] I get that. But why is it rewritten to http://www.domain.com/images/pic.jpg? I would've thought it would just try to find subdomain.domain.com/images/pic.jpg and failing that, give a 404 error. Rewriting image directory for a dynamic subdomain - El Forum - 03-03-2009 [eluser]TheFuzzy0ne[/eluser] Oh I see. Is it possible you have a ninja htaccess file stealthily hiding in one of your other subdirectories, waiting to pounce on unsuspecting URIs with its cat-like reflexes? |