Forum Moderators: phranque
RewriteRule ^([0-9]+)/.*--(.*)\.(jpg¦png¦gif)$ /images/$1-$2.$3
Basically I am trying to change the actual image name like 12345-name_of_the_file.gif in my images directory into a an neat URL like 12345/some_dynamic_keyword_related_text--name_of_the_file.gif
I think the rule looks good but I am getting a 500 Internal Server Error message with it in my .htaccess. I am probably missing something stupid here (like maybe it's impossible to do what I'm trying to do.)
and the "real" URL to each of these files would be /images/$1-$2.$3
images/58289--filename.png
images/91046--another_filename.gif
images/00376--not_so_cool_filename.jpg
I think I got that part right. Am I even more confused than I thought? :?
If this is the first, you'll need to set an Option to enable mod_rewrite and also start the Rewrite Engine
Options +FollowSymLinks
RewriteEngine on
Note that the Options directive above is either
1) Required and allowed by your host
2) Not required, but allowed by your host
3) Not required, and not allowed by your host
4) Required, but not allowed by your host
Only testing will determine which of these is the case. For case (4), you cannot use mod_rewrite.
Take a look at your server error log; The message associated with the 404 will likely be quite useful in diagnosing the problem, since it will tell you where the server is actually trying to find the file.
Jim
Thanks for the advice. :)
I think that I would need to allow - but I think I am starting to see why the . in there could cause a problem (which also leads me to see why the - could be a problem.) The dot shouldn't be necessary so I can str_replace() it with - and maybe replace -- with - when saving the image and use ^([0-9]{5})/[^.]+--([^.]+)\.(jpe?g夙if如ng在mp)$
Am I getting this yet?
"[^.]+" means, "Accept one or more characters not equal to a literal period." Or alternately in this project's context, "match all characters up to the period before the filetype."
The only characters that need to be escaped within [groups] are "]", "\", <space>, and in some positions, "^" and "-". At the beginning of a [group], "^" means "NOT".
Jim
Anyway, Thank you so much jd. I read in another thread that somebody says you don't know what you're talking about. For the record, that guy's an idiot.
P.S. thanks to this thread, I finally [understand] this: /(bb¦[^b]{2})/
[from a T-shirt at thinkgeek] lol
[edited by: jdMorgan at 3:37 am (utc) on July 19, 2007]
[edit reason] No URLs, please. [/edit]
In language, we use OR differently than in formal logic. In logic, the result is true if either or both is true. But in speech we assume that both will not be true, in a way more like the logical XOR (exclusive OR) operator.
Jim