regex - URL rewriting for images with different domains -
i want use urls followings :
http://mydomain.com/320x200/server/path/to/my/image.jpg
where can find 3 parameters retrieve rewriting :
320x200
: optional parameter, can 2 numbers (like "320x200"), or single number (like "320x") or empty (only "x")server
: required (this specific parameter find server image hosted, not matter case)path/to/my/image.jpg
: required
and rewrite domain followings :
http://myotherdomain.com/320/200/server/path/to/my/image.jpg
i tried following rewrite rules not working :
rewriterule ^([0-9]+)x([0-9]+)/([a-za-z0-9]+)/([a-za-z0-9/.]+)$ htp://myotherdomain.com/$1/$2/$3/$4 [l]
rewriterule ^([0-9]+)x/([a-za-z0-9]+)/([a-za-z0-9/.]+)$ htp://myotherdomain.com/$1/$2/$3 [l]
rewriterule ^x/([a-za-z0-9]+)/([a-za-z0-9/.]+)$ htp://myotherdomain.com/$1/$2 [l]
why not working ?
the 3 regex working when tested through website regexplanet.com
i tried clear browser cache, restart apache, remove cookies, ... still not working !
thanks help
edit :
finally, problem .htaccess file not correctly saved (don't know why).
i closed , opened .htaccess again, ok !
you should divide work grouping. don't bother converting x
/
don't capture it.
rewriterule ^([0-9]+)x([0-9]+/)([a-za-z0-9]+)/([a-za-z0-9/.]+)$ http://myotherdomain.com/$1/$2$3/$4 [l] rewriterule ^([a-za-z0-9]+)/([a-za-z0-9/.]+)$ http://myotherdomain.com/$1/$2 [l]
([0-9]+)
captures 2 resolutions parameters individually.(?:....)?
non capturing grouping rendered optional.
edit:
the optionality trap. don't use -> second rule.
if other domain end being same domain:
rewritecond %{request_uri} ![0-9]+/[0-9]+.*$
will prevent loops.
Comments
Post a Comment