#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Location
    Arizona
    Posts
    56
    Rep Power
    10

    .htacccess and pointing files up the directory tree


    Hello,

    I am running WAMP and working with localhost. I want to configure my local setup so it works identically as my live site. On my live site I use an absolute path, e.g.

    <img src="/path/to/image.jpg" />

    Now WAMP is set up normally, i.e. c:\wamp\www\my_directory. .htaccess in located in /www. However, the above src resolves to http://localhost/path/to/ instead of http://my_site/path/to/ . Essentially I need to push the resolving path up the directory tree. I've played around with RewriteBase and all sorts of RewriteRules without any luck. Can someone recommend a solution? Thanks a lot for the help.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,112
    Rep Power
    9398
    Originally Posted by ebakunin
    Essentially I need to push the resolving path up the directory tree.
    Not really. What you "need" to do is to completely change the site where the files are coming from. That's a lot more than merely changing some directory.

    Do you want all /path/to/* files to come from the live site? All JPEG images? All images?
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Location
    Arizona
    Posts
    56
    Rep Power
    10
    Originally Posted by requinix
    Do you want all /path/to/* files to come from the live site? All JPEG images? All images?
    Not at all. I just want to use this style of absolute path (src="/path/to/file.jpg") in both my local and live site. With my live site it's not an issue. It's just my local that's being a pain-in-the-***.
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,112
    Rep Power
    9398
    Lemme make sure I understand this: your problem is that some of your paths go to localhost when you want them to go directly to your live site instead?
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Location
    Arizona
    Posts
    56
    Rep Power
    10
    Originally Posted by requinix
    Lemme make sure I understand this: your problem is that some of your paths go to localhost when you want them to go directly to your live site instead?
    No. I apologize. I must not be explaining myself well. Let me try again.

    On my live site, src="/path/to/site.jpg" will resolve to http://www.my_site.com/path/to/site.jpg. On my local, it will resolve to http://localhost/path/to/site.jpg, bypassing the my_site.com directory altogether. I want to use my local .htaccess to make sure the image resolves to http://localhost/my_site.com/path/to/site.jpg, as expected.

    Thanks for the help.
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,112
    Rep Power
    9398
    Okay... So when you're working on the site locally you need everything to come out of the C:\wamp\www\my_site.com directory? Because you actually have a "my_site.com" folder right there and that's where all the code and images and stuff reside?

    Why not forgo the my_site.com folder and just put everything in C:\wamp\www?
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Location
    Arizona
    Posts
    56
    Rep Power
    10
    Originally Posted by requinix
    Okay... So when you're working on the site locally you need everything to come out of the C:\wamp\www\my_site.com directory? Because you actually have a "my_site.com" folder right there and that's where all the code and images and stuff reside?

    Why not forgo the my_site.com folder and just put everything in C:\wamp\www?
    Sorry for the delay.

    Because I have multiple sites I want to work on, e.g. c:\wamp\www\my_site.com, c:\wamp\www\my_other_site.com, etc. Since \www is localhost, I can't have multiple sites unless the directories extend from \www instead of residing in \www. Again, every site build on localhost works fine, except when the path is /path/to/image.jpg.

    Does that make sense? Thanks.
  14. #8
  15. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,112
    Rep Power
    9398
    That's what I figured. And yes, it makes sense.

    The thing is this. Imagine for a minute that you're Apache and you've just been asked for the "/path/to/site.jpg" image. Where do you go for that? How do you know it's supposed to be under my_site.com and not my_other_site.com?

    You can do this pretty easily by telling Apache "if you can't find it then look in my_site.com instead", but you'll only be able to have it working for one site at a time. When you start working on a different site you'd have to go to the configuration and update it for the new site.
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Location
    Arizona
    Posts
    56
    Rep Power
    10
    Originally Posted by requinix
    That's what I figured. And yes, it makes sense.

    The thing is this. Imagine for a minute that you're Apache and you've just been asked for the "/path/to/site.jpg" image. Where do you go for that? How do you know it's supposed to be under my_site.com and not my_other_site.com?

    You can do this pretty easily by telling Apache "if you can't find it then look in my_site.com instead", but you'll only be able to have it working for one site at a time. When you start working on a different site you'd have to go to the configuration and update it for the new site.
    What would that RewriteRule look like?
  18. #10
  19. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,112
    Rep Power
    9398
    At least I have one more thing up my sleeve.
    Code:
    # not a file
    RewriteCond %{REQUEST_FILENAME} !-f
    # not a directory
    RewriteCond %{REQUEST_FILENAME} !-d
    # assume it's in my_site.com
    RewriteRule ^ my_site.com%{REQUEST_URI} [L,R]

IMN logo majestic logo threadwatch logo seochat tools logo