Exploding Garrmondo Weiner Interactive Swiss Army Penis

Exploding Garrmondo Weiner Interactive Swiss Army Penis (http://www.gamingforce.org/forums/index.php)
-   Help Desk (http://www.gamingforce.org/forums/forumdisplay.php?f=36)
-   -   .htaccess aids (http://www.gamingforce.org/forums/showthread.php?t=21687)

Roph May 29, 2007 11:09 AM

.htaccess aids
 
So I'm rewriting

http://slyph.org/music/kylelandry/vi...asie_Impromptu to http://slyph.org/music/kylelandry/vi...sie_Impromptu/ , though I can't get it to work if the htaccess'd url is missing an end slash.

Here's the contents of my .htaccess,

Code:

Options +FollowSymLinks
RewriteEngine on
ReWriteBase /music/kylelandry/video/
RewriteRule play/(.*)/ index.php?play=$1
RewriteRule play/(.*) index.php?play=$1

I'd have thought the last line would have made requests without the end slash (http://slyph.org/music/kylelandry/vi...asie_Impromptu for example) work fine, though it just comes back with the error I made my script spit out when the video request doesn't match an array of all the videos there.

Going to investigate further, though I'm not sure what I'm going to do, as that htaccess looks perfect to me :gonk:

[edit] Ok, I updated my script so that if it is a bad request then it'll echo what the request was, and it looks like the / in my variables is fucking with it. When requesting one without the end /:

Quote:

Invalid Video selected!
(testing, request was "Classical")
Uhh, :gonk:

Snowknight May 29, 2007 02:37 PM

If I'm remembering correctly, the existence of URLs without a trailing slash requires that you do something like this for the second RewriteRule:

Code:

RewriteRule play/(.*)/(.*) index.php?play=$1$2
I'm not making any guarantees, though; I've never really used mod_rewrite much. If all else fails, you could make your PHP add a trailing slash when one does not exist.

THE POWER OF WATER May 29, 2007 04:15 PM

Instead of this:

Code:

RewriteRule play/(.*)/ index.php?play=$1
RewriteRule play/(.*) index.php?play=$1

Do this:

Code:

RewriteRule play/(.*)/? index.php?play=$1
A question mark means to match 0 or 1 of the previous character or group, which in this case is the slash.

Roph May 29, 2007 06:33 PM

That makes it work for requests without the end slash, though breaks it when a slash is used ;_;

Quote:

Invalid Video selected!
(testing, request was "Classical/Chopin_-_Fantasie_Impromptu/")
Hmm, I think I'll just stick with this though and remove the end slash if present with PHP.

Thanks for the help =D

Fleshy Fun-Bridge May 29, 2007 09:08 PM

I think your real problem is that the regex pattern .* is greedy, in that it will try to match the longest string of text possible. Given the text:

/play/Classical/Chopin_-_Fantasie_Impromptu/

/play/(.*)/? will always include the trailing slash in the match because it still satisfies the pattern and is longer than a match without the slash. The solution is to use a non-greedy qualifier such as /play/(.*?)/? instead. That will try to match as little text as possible while satisfying the pattern.


All times are GMT -5. The time now is 01:39 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2025, vBulletin Solutions, Inc.