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. :rolleyes::smiley:

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

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.

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

Well, this is what i ended up with by following examples on the internets :stuck_out_tongue:

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)

SL,

Noone ever taught you to check your sources?

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

When it failed, yup. S’why I came here :stuck_out_tongue:

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.

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

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?

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

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]

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 :slight_smile:

SL,

GREAT! :Partier: If it works, don’t fix it!

Regards,

DK