SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: The Basics

  1. #1
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)

    The Basics

    Ohai.

    So, time for me to sit down and actually learn some of this URL rewriting stuff that I havent actually bothered to learn yet.

    I'm trying to do this, but just getting a 404 error;

    Code:
    Options +FollowSymLinks
    
    RewriteEngine on
    RewriteBase /spamable/
    RewriteCond %{QUERY_STRING} !id=(.*)$ [NC]
    RewriteRule ^(.*)\.flv$ index.php?id=$1 [L]
    the idea is to make a directory in which i can call any file name (ending in .flv) and push it invisibly to index.php, so i can throw some junk data out.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    SL,

    What's the RewriteBase supposed to be doing? If you're not familiar with it, it's supposed to "undo" mod_alias redirections so mod_rewrite can work on the URIs so, in this case, it looks like you're DocumentRoot is in the example.com/spamable// directory.

    Then, what's the RewriteCond supposed to do? You're not using it and /spamable//{whatever}.flv should never have a query string.

    That looks more like a "venus fly trap" sort of code (not suitable for index.php but a handle_spam.php script). Nice but it will cost you some bandwidth (and, hopefully, keep your hackers amused for a while).

    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

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Well, this is what i ended up with by following examples on the internets :P

    The idea is this.
    Whatever URL comes in in the form of http://internal.domain/spamable/(anything).flv, i want to actually respond with data, without sending a redirect.
    The reason for doing it is an internal project needs to be able to call out for a theoretically infinite number of unique filenames (1.flv, 2.flv, etc etc etc) and not get served a 404, or 30X, but a 200.

    the content itself is unimportant (not a valid FLV), just that -some- data is sent back in a 200 message. (The test here is of an intermediary streaming server, that will be HTTP-GET'ing content from this directory as a remote source)
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    SL,

    Quote Originally Posted by StarLion View Post
    Well, this is what i ended up with by following examples on the internets :P
    Noone ever taught you to check your sources?

    Quote Originally Posted by StarLion View Post
    The idea is this.
    Whatever URL comes in in the form of http://internal.domain/spamable/(anything).flv, i want to actually respond with data, without sending a redirect.
    The reason for doing it is an internal project needs to be able to call out for a theoretically infinite number of unique filenames (1.flv, 2.flv, etc etc etc) and not get served a 404, or 30X, but a 200.

    the content itself is unimportant (not a valid FLV), just that -some- data is sent back in a 200 message. (The test here is of an intermediary streaming server, that will be HTTP-GET'ing content from this directory as a remote source)

    Ah! Specificity!

    Try:

    Code:
    # .htaccess in DocumentRoot
    
    RewriteRule ^spamable/([^/]+)\.flv$ index.php?id=$1 [L]
    Your FollowSymLinks will already be in the httpd.conf, the RewriteBase only confuses the target (and redirection) and the query string is clearly not needed (and is not used in your code) - even as an exclusion.

    Until you're happy with the redirection, you should change the flag to [R=301,L] so you can see the redirection but remove the R=301 and comma before going live (because you want to hide the index.php serving the response).
    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    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

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    SL,
    Noone ever taught you to check your sources?
    When it failed, yup. S'why I came here :P
    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.
    Read it; it was actually missing a step (my httpd.conf file included both <Directory /> and <Directory /var/www/html> (docroot), which both set AllowOverride to None; your tutorial changes the /, but didnt mention the docroot one, so i didnt go looking for it at first).

    This also meant i needed a RewriteBase directive in my htaccess - otherwise i'd get URLs out in the form http://internal.domain/var/www/html/index.php , which of course failed.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    SL,

    As a Mentor, you only came to SP when someone else's code failed? ;( Oh, well.

    Hmmm, I've never seen a 'nix httpd.conf with a <Directory> pointing to the server root so that would be an obvious error ... but on whose part? Thank you for that feedback, though!

    RewriteBase has nothing to do with your server's file structure. Its intent is to undo a mod_alias redirection so mod_rewrite can work on the URI. WP misuses it to enable their code to reside in a subdirectory but that's another issue. If it works for WP, I'd not "fix it" but I would never use RewriteBase otherwise.

    Finally, when you get URLS like domain/server_path/to/file rather than domain/path/to/file, that's indicative of a problem with the server which can (only?) be cleared by restarting Apache. I have no information on the error causing this sort of redirection except that it's obviously wrong.

    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

  7. #7
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    SL,

    As a Mentor, you only came to SP when someone else's code failed? ;( Oh, well.
    My habit is to try the immediate thing, and then seek help. *shrug* When you've got a deadline, things have to get done.

    Hmmm, I've never seen a 'nix httpd.conf with a <Directory> pointing to the server root so that would be an obvious error ... but on whose part? Thank you for that feedback, though!
    All i can say is that it was in the default HTTPD package install with the RHEL 6.2 image I was cloning for a virtual.


    RewriteBase has nothing to do with your server's file structure. Its intent is to undo a mod_alias redirection so mod_rewrite can work on the URI. WP misuses it to enable their code to reside in a subdirectory but that's another issue. If it works for WP, I'd not "fix it" but I would never use RewriteBase otherwise.
    This isnt a WP installation.

    Finally, when you get URLS like domain/server_path/to/file rather than domain/path/to/file, that's indicative of a problem with the server which can (only?) be cleared by restarting Apache. I have no information on the error causing this sort of redirection except that it's obviously wrong.
    Possibly related to the Directory definition for /server_path/to/ in httpd.conf?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    Hi SL!

    Yeah, I try to get everything done to a deadline (my taxes are always submitted on the due date - I ***LOATHE*** doing taxes).

    Okay, weird configuration of your RedHat installation. They must have a reason for that but I can't guess what it must be.

    WP has nothing to do with RewriteBase except for the only valid use I've seen for using it (IMHO).

    No, Apache is "smart enough" to keep the server file structure separate from a domain's DocumentRoot (which must be defined to Apache in terms of the server's file structure). I have yet to figure out why the server path gets inserted into a URL (this should NEVER happen) so, for me, a restart is the only way out of that box.

    Back to your original problem: Did
    Code:
    RewriteRule ^spamable/([^/]+)\.flv$ index.php?id=$1 [L]
    work for you as you needed?

    Regards,

    DK
    All i can say is that it was in the default HTTPD package install with the RHEL 6.2 image I was cloning for a virtual.



    This isnt a WP installation.


    Possibly related to the Directory definition for /server_path/to/ in httpd.conf?[/QUOTE]
    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

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    I needed a RewriteBase to circumnavigate the odd server-path-injection bit, and a slight rewrite to the rule (adding the spamable/ directory to the redirected url), but yes, this now works
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    SL,

    GREAT! If it works, don't fix it!

    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
  •