SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: RewriteEngine

  1. #1
    SitePoint Enthusiast escocia1's Avatar
    Join Date
    May 2001
    Location
    oaxaca, mexico
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RewriteEngine

    i found this code in my .htaccess file

    Redirect /demo http://www.dosvatos.com/Demo

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?dosvatos.com/.*$ [NC]
    RewriteRule \.(gif|jpg|js|css|mov)$ - [F]

    not sure what it does
    but its causing problems lower down in subdomains where other sites arent bringing in images correctly
    is there a way to make this apply only to the top level main domain dosvatos.com ?
    David Sutherland

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,145
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    forbidden images

    The line
    RewriteCond %{HTTP_REFERER} !^$
    says "if the HTTP referrer is NOT empty"
    the line
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?dosvatos.com/.*$ [NC]
    says "if the HTTP referrer is not a page in the dosvatos.com domain (with or without the www - case insensitive)"
    If you have sub-domains that don't begin with dosvatos.com, you could add them under the dosvatos condition, using their domain names.
    Since the images are still available when the HTTP_REFERER is absent or forged, you could also simply not use the rewrite.

  3. #3
    SitePoint Enthusiast escocia1's Avatar
    Join Date
    May 2001
    Location
    oaxaca, mexico
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the quick response!
    i took out the rewrite altogether and the images load fine
    still not sure why that code was there in the first place?
    whats it doing anyway? something related to visitor statistics and referrers?

    how would i add my other domains?
    i'll take a stab in the dark:

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?dosvatos.com/.otherdomain.com/.otherdomain2.com/.*$ [NC]
    RewriteRule \.(gif|jpg|js|css|mov)$ - [F]
    David Sutherland

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,145
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    hot-linking

    It's to keep sites from hot-linking to your files. Say I like one of your jpgs, but I don't want to keep a copy on my server. I link to your site like
    HTML Code:
    <img src="http://www.yourdomain.com/cool.jpg">
    Or I want to see your javascript file (and I don't know how to use browser dev tools), then I make a direct HTTP request for http://www.yourdomain.com/cool.js
    This will deter hot-linking and snooping somewhat. Some browsers don't have referer enabled, hence the "if not empty".
    IMHO it's better to protect files with server-side script.

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Gudonya, Mitt, for your excellent response. IMHO, mod_rewrite is a VERY useful tool but one that should ONLY be used if you know what you're doing (i.e., don't use canned programs).
    Quote Originally Posted by Mittineague View Post
    IMHO it's better to protect files with server-side script.
    I would suggest that mod_rewrite is the best first line of defense against bandwidth these but using code which takes subdomain redirects (to the DocumentRoot, i.e., through .htaccess) into account.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

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