Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Question Disable View File Using Htaccess

    Hey Guys,

    Just wondering if it's possible with htaccess to say disable viewing of all text files on my server? Like they are still accessible if a script calls them but not if you just type out the direct url into your browser.

    If so how might I do this?

    Thanks again! +Rep for replies!
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You can use this
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http://yoursite.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://yoursite.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.yoursite.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.yoursite.com$      [NC]
    RewriteRule .*\.(txt)$ - [F,NC]
    You can prevent other files from being accessed by typing in the url by adding a | and the file extension. For example this will prevent hotlinking of your images as well
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http://yoursite.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://yoursite.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.yoursite.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.yoursite.com$      [NC]
    RewriteRule .*\.(jpg|jpeg|gif|png|bmp|txt)$ - [F,NC]
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thanks for the code except one thing.....

    When I tried using it I got a 500 error :S anyone know why? Thxs
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What kind of server are you using? Apache or Windows? Did you actually change yoursite.com to your url?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Apache on Windows

    Yes I changed url.
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Yeah I've had problems using htaccess with apache on Windows. Are you by chance using XAMPP?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Yes I would be....?
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Yeah I was never able to get an htaccess file to work with xampp. Aha! Just did some googling. It turns our mod_rewrite isn't turned on by default. Article that says to get it enabled here
    http://www.mydigitallife.info/2006/0...n-xampp-setup/
    The article discusses permalinks but I think using the advice from the article might make htaccess file on xampp work as they should. *Goes to test out the theory*
    Last edited by _Aerospace_Eng_; 06-10-2007 at 12:50 AM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #9
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Okay thxs

    I'll take a look
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Yep after following the advice in that article, htaccess worked as it should, got no 500 error and hotlinking of txt files was disabled. In the latest version of XAMPP 1.6.2 you only have to enable the mod_rewrite module. You may have to change the code a bit to look something like this
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http://localhost/folderwherefilesareat/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://localhost/folderwherefilesareat$      [NC]
    RewriteRule .*\.(jpg|jpeg|gif|png|bmp|txt)$ - [F,NC]
    Since its your localhost, I don't know.
    Last edited by _Aerospace_Eng_; 06-10-2007 at 12:53 AM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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