Click to See Complete Forum and Search --> : [RESOLVED] Keeping stuff on localhost from being accessed by other sites.
Mr Initial Man
11-23-2009, 03:41 AM
I keep a mirror of every site I run on my hard drive, so that I can work with them. Sometimes, however, I run into a problem if I use a <base> element: I forget to upload the include for the site, and my viewers get <base href="http://localhost/...">, which clearly causes problems.
How do I set up localhost so that files from localhost can ONLY be accessed on a localhost site?
opifex
11-24-2009, 06:12 AM
Try using a config file to set things like base url, data base info, etc. (like most cms) and use one copy for localhost and a "live" copy for the live site.
Do the same with your .htaccess file... there could be conflicts between localhost and live server there also.
Mr Initial Man
11-24-2009, 12:32 PM
If I have Apache, how do I do that? Sorry, I seldom mess with .htaccess. >_<
opifex
11-24-2009, 11:34 PM
Are your sites static or dynamic?
In general, using <base> in a static site makes portability a little more difficult because you need to change the base reference on each page.
An option would be to "embed" PHP in your html or use ssi (cgi)... allowing you to include text from a (config) file.
Mr Initial Man
11-25-2009, 05:12 PM
Dynamic. And yes, I use <base>. I have one head include for localhost, one for the live website. Basically, what I want is this: If I upload the wrong head include, I want my stylesheets not to work and images not to show up, so that I know at once something is wrong.
opifex
11-25-2009, 05:42 PM
????
OK I guess you want to do the reverse of the "norm" - create everything so it is incompatible...
Simple... use different folder names the and css for live and testing... no css if the wrong "head" file gets uploaded.
Mr Initial Man
11-25-2009, 05:52 PM
I thought there was a .htaccess trick you could use to keep images and such from being used outside of the domain (i.e. hotlinked.)
opifex
11-25-2009, 06:37 PM
now I'm confused!
what is the problem again? unless your hard drive is accessible to the general public via internet... possible, but NOT a good idea, and you are using your internet IP address and route to your localhost in your <base> (not 127.0.0.0) you can't see the photos from your hard drive on the live site.
Mr Initial Man
11-25-2009, 06:58 PM
Okay. For the mirror on my computer, I have the following base URL:
<base href="http://localhost/FBA/">
For the live site, I have:
<base href="http://fba.furtopia.org/">
Both are contained in a file known as "head.htm". If I upload the wrong "head.htm" to the site, then the live site will point to "http://localhost/FBA/". All fine and dandy for me, since my browser can find it, and I don't notice anything's amiss until someone emails me and asks me why the site is not working. What I want is to keep my CSS files and images from being hotlinked from my localhost so that if I upload the wrong "head.htm", the site won't work for me.
opifex
11-25-2009, 09:05 PM
You might try this then...
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://localhost/FBA/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|png|svg|jar|js|css)$ - [NC,F,L]
It goes in the .htaccess in the localhost/FBA folder. No reason it shouldn't work for what you want, but can't be sure.
Mr Initial Man
11-26-2009, 01:08 AM
Thank you. :-) That worked wonders.