The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> System Administration
> Apache Development
|
mod_rewrite - .htacccess and pointing files up the directory tree
Discuss .htacccess and pointing files up the directory tree in the Apache Development forum on Dev Shed. .htacccess and pointing files up the directory tree Apache Development forum discussing HTTP Server general topics, configuration, and modules. Apache is an open source web server that runs on multiple platforms.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 3rd, 2012, 09:45 PM
|
 |
Contributing User
|
|
Join Date: Feb 2005
Location: Arizona
Posts: 56
Time spent in forums: 1 Day 1 h 35 m 41 sec
Reputation Power: 9
|
|
|
mod_rewrite - .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.
|

March 4th, 2012, 03:19 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Quote: | 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?
|

March 4th, 2012, 03:39 AM
|
 |
Contributing User
|
|
Join Date: Feb 2005
Location: Arizona
Posts: 56
Time spent in forums: 1 Day 1 h 35 m 41 sec
Reputation Power: 9
|
|
Quote: | 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-***.
|

March 4th, 2012, 03:53 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
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?
|

March 4th, 2012, 04:11 AM
|
 |
Contributing User
|
|
Join Date: Feb 2005
Location: Arizona
Posts: 56
Time spent in forums: 1 Day 1 h 35 m 41 sec
Reputation Power: 9
|
|
Quote: | 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.
|

March 4th, 2012, 04:38 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
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?
|

March 4th, 2012, 03:18 PM
|
 |
Contributing User
|
|
Join Date: Feb 2005
Location: Arizona
Posts: 56
Time spent in forums: 1 Day 1 h 35 m 41 sec
Reputation Power: 9
|
|
Quote: | 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.
|

March 4th, 2012, 04:40 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
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.
|

March 4th, 2012, 10:01 PM
|
 |
Contributing User
|
|
Join Date: Feb 2005
Location: Arizona
Posts: 56
Time spent in forums: 1 Day 1 h 35 m 41 sec
Reputation Power: 9
|
|
Quote: | 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?
|

March 4th, 2012, 10:47 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
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]
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|