Friday, 6 September 2013

Apache rewrite remove .jpg.html from URL

Apache rewrite remove .jpg.html from URL

I've been trying to write a rewrite rule for apache to switch my gallery2
URLs to the gallery3 URL format:
Old url example linked:
http://domain.com/gallery/photoalbumxyz/photo.jpg.html
New url example needed: http://domain.com/photos/photoalbumxyz/photo
Note that in the URL example above, "/photoalbumxyz/photo.jpg.html" is not
an actual physical directory, it is just the way gallery2 rewrote
"friendly" URLs. I can rewrite the /gallery/ to /photos/ by using a rule
like the following:
RewriteRule ^(.*)$ /photos/$1 [QSA,L,R=301]
However I'm having trouble figuring out the matching and removal of the
".jpg.html" extension if it exists in combination with the /gallery/ ->
/photos/ rewrite. The regex matching I believe is going to be .jpg.html to
escape the periods, but how do I write rules to remove the ".jpg.html"
extension and rewrite the directory?
RewriteRule ^\.jpg\.html$ $1 [NC]
RewriteRule ^(.*)$ /photos/$1 [QSA,L,R=301]

No comments:

Post a Comment