Forum Moderators: phranque
RewriteRule ^(.*)/(.*)/(.*)/(.*)$ thing.php?$1=$2&$3=$4
to rewrite this:
< [yourdomain.com...] >
to this:
< [yourdomain.com...] >
how can I edit that rule so that I am rewriting from this:
< [yourdomain.com...] >
--
The script I am attempting to do this with generates an image on the fly. I would like the .png/.jpg/.gif extension to be appended.
Thanks in advance :)
RewriteRule ^(.*)/(.*)/(.*)/(.*\.png)$ thing.php?$1=$2&$3=$4
doesnt break the script entirely.. In fact, its displaying the image when you call it up, except that the last query (4) doesnt seem to be beiung respected -- that might be the fault of the php script though.
Assuming the example above is how i ought to be doing this?
the first variable is successfully being passed to the PHP script responsible for the output (it's using simple $_GET's)
however, the last variable isnt being passed .. the PHP script is set up to output a default setting if that variable isnt set, and additionally, thats what it's echoing back, so Ive verified this 2x)
Im at a loss.
This will be processed many, many times faster:
^([^/]+)/([^/]+)/([^/]+)/([^.]+)\.png$
If you use "(.*)/(.*)"-type patterns, the parser will initially attempt to match all of the requested URL-path into the first "(.*)" subpattern because ".*" means "Match any characters, and as many as possible."
This will fail, so the parser will 'move' one character out of the first subpattern and try again. This try-and-fail will repeat until the URL-path is correctly apportioned to the two "(.*)" subpatterns and results in a match, or until all possible combinations are tried and fail.
Now imagine what happens when you have three "(.*)" patterns in a row -- The number of trial matches goes way up. With four or more, it can become a huge number -- tens of thousands.
Also, be aware that the pattern "^(.*)/(.*)/(.*)/(.*\.png)$" will match any of the following requested URLs, which is probably not what you want:
a/b/c/d.png (expected URL format)
a/b/c/d/e.png (one 'directory' longer
a/b/c/d/e/f.png (two 'directories' longer)
etc.
In other words, any URL of the form a/b/c/d.png or longer. You will find that the 'extra' path-parts end up in $1. For example, the second example URL-path "a/b/c/d/e.png" will result in a rewrite to "thing.php?a/b=c&d=e"
".*" subpatterns are 'easy' but can dangerous. If used multiple times in one pattern, they can be very slow to process and can produce unexpected results. Avoid them whenever possible.
Jim