Hi Yath!
No worries.
It was a bit confusing (to me) the way that your code was written. Since the HTTP is not required and some other things could be better coded (IMHO, of course), let me give it a try.
[COLOR="#A9A9A9"]# RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\\s/+viewgallery\\.php\\?cname=([^&]+)&pcaption=([^&\\s]+) [NC]
#RewriteRule ^ /photos/%1/%2.jpg? [R=302,L,NE][/COLOR]
RewriteCond %{THE_REQUEST} viewgallery\\.php?cname=([^&]+)&pcaption=([^&]+)[COLOR="#0000FF"]\\.jpg[/COLOR]
# This eliminates the HTTP with version, the \\ in front of the ?,
# the space in the pcaption's character range definition and
# the No Case flag (you're using range definition which don't specify capitalization)
# Don't you need the .jpg stripped or is this handled by your viewgallery script?
RewriteRule .? photos/%1/%2.jpg? [R=301,L]
# I prefer an optional character to a start anchor followed by nothing but label that personal preference.
# If this is in your website's DocumentRoot, the leading / in the redirection is not required
# (and will tell Apache to look at the [B]server's root[/B] before the website's DocumentRoot).
# 301 is a permanent redirect and forces browsers to display the .jpg link.
# I removed the NE flag ("noescape|NE Prevent mod_rewrite from applying [I]hexcode escaping of special characters[/I]
# in the result of the rewrite.") because I don't understand what you're trying to do with it.
The first one basically detects if request is made for /viewgallery.php?cname=foo&pcaption=bar while capturing foo & bar.jpg in %1 and %2.
Then it make external redirection of that request to /photos/%1/%1 i.e. /photos/foo/bar (where bar ends with .jpg)
RewriteRule ^photos/([^/]+)/([^.]+)\\.jpg$ /viewgallery.php?cname=$1&pcaption=$2 [[COLOR="#FF0000"]QSA[/COLOR],L,NC,NE]
This rule works matches any /photos/foo/bar request and internally forwards that to /viewgallery.php?cname=foo&pcaption=bar&{prior query string}
So /viewgallery.php?cname=foo&pcaption=bar is always the call that is made to PHP code but a user will always send /photos/foo/bar from the browser.
I’m a bit concerned over the .jpg and any prior query string so please label this as another source of confusion (for me).
I removed this now.You did mention this before. Careless me…left this on again.
That’s merely a “pet peeve” of mine as it generally does nothing at all … but could cause unexpected redirections.
I am not sure how to answer this. As I understand that is the part that converts the ugly part ‘/viewgallery.php?cname=foo&pcaption=bar’ to the format I would like to have which is ‘/photos/foo/bar.jpg’.
Here is the live demo of these rules. http://http://www.rajeevthomas.com/photos/Colorado-Fall/Touched-By-Light.jpg
I don’t know if I am wishing for too much here…but I would like the link to show up without ‘photos’ to make it show up as www.xyz.com//foo/bar or www.rajeevthomas.com/Colorado-Fall/Touched-By-Light but whenever I tried to do that , it lead to massive errors or images never showed up!.
Hope this explains everything…I am still such a newbie about all this… thank you for you help DK…
Actually, because this is so different than normal treatment (are your images provided as stand alone rather than embedded in web pages?) that it has led to confusion on my part … and, especially with the .jpg issue, probably on yours. Otherwise, I’d suggest kudos for how far you’ve gotten!
Regards,
DK