www.webdeveloper.com
Results 1 to 11 of 11

Thread: [RESOLVED] Keeping stuff on localhost from being accessed by other sites.

  1. #1
    Join Date
    Sep 2004
    Location
    At the corner of WALK and DONT WALK
    Posts
    1,741

    resolved [RESOLVED] Keeping stuff on localhost from being accessed by other sites.

    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?

  2. #2
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    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.

  3. #3
    Join Date
    Sep 2004
    Location
    At the corner of WALK and DONT WALK
    Posts
    1,741
    If I have Apache, how do I do that? Sorry, I seldom mess with .htaccess. >_<

  4. #4
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    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.

  5. #5
    Join Date
    Sep 2004
    Location
    At the corner of WALK and DONT WALK
    Posts
    1,741
    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.

  6. #6
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    ????
    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.

  7. #7
    Join Date
    Sep 2004
    Location
    At the corner of WALK and DONT WALK
    Posts
    1,741
    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.)

  8. #8
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    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.

  9. #9
    Join Date
    Sep 2004
    Location
    At the corner of WALK and DONT WALK
    Posts
    1,741
    Okay. For the mirror on my computer, I have the following base URL:

    HTML Code:
    <base href="http://localhost/FBA/">
    For the live site, I have:

    HTML Code:
    <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.

  10. #10
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    You might try this then...
    Code:
    RewriteEngine on
    
    RewriteCond &#37;{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.
    Last edited by opifex; 11-25-2009 at 10:36 PM.

  11. #11
    Join Date
    Sep 2004
    Location
    At the corner of WALK and DONT WALK
    Posts
    1,741
    Thank you. :-) That worked wonders.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles