In the .htaccess
file located in the subdirectory at /library/photography/.htaccess
you can do something like the following using mod_rewrite to internally rewrite the request to the desired URL.
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)cmd=image(&|$)
RewriteCond %{QUERY_STRING} (?:^|&)sfpg=([^&*]+)\*([^&]+)(&|$)
RewriteRule ^index\.php$ %1%2 [QSD,L]
The first condition (RewriteCond
directive) simply confirms that the cmd=image
URL parameter is present anywhere in the query string.
The second condition captures the parts of the sfpg
URL parameter value surrounding the *
character (which needs to be backslash-escaped when used outside of a regex character class in order to negate its special meaning). These are then available in the %1
and %2
backreferences respectively and used in the substitution string (2nd argument of the RewriteRule
directive) is construct a relative file-path (ie. relative to the /library/photography/
subdirectory that contains the .htaccess
file).
There URL parameters can appear in any order. eg. ?sfpg=folder/*image.jpg&cmd=image
would also successfully match. And there can be additional URL parameters, which are discarded.
The QSD
(Query String Discard) flag removes the original query string from the rewritten request (not that it really matters for an internal rewrite).
Aside:
RewriteRule /index.php /
This doesn't really make sense as an internal rewrite, since both /index.php
and /
should return the same resource. (This would ordinarily be implemented as an external redirect in order to resolve any SEO issues with regards to duplicate content.)
UPDATE:
I think I found a problem in the general approach, however. The actual files do not reside where the link would imply. Please see my updated question.
If I understand your update correctly, the "real file" that you wish to serve is stored in the synced
subdirectory and the sfpg
URL parameter refers to the file-path within that subdirectory (less the *
)? (Which is all within the /library/Photography
subdirectory, including the .htaccess
file. Or at least the .htaccess
file that we are working on here.)
In which case, you would only seem to need to modify the RewriteRule
directive by prefixing the substitution string with synced/
. For example:
:
RewriteRule ^index\.php$ synced/%1%2 [QSD,L]
(Everything else remains unchanged from the rule above, at the top of my answer.)