NextGEN Gallery Lightbox – Social Share URL Redirect

You could do something like the following in .htaccess before the existing WordPress directives.

RewriteCond %{QUERY_STRING} ^uri=(/[^&]+)
RewriteRule ^nextgen-share/(\d+/\d+)/full$ %1#gallery/$1 [QSD,NE,R,L]

The RewriteRule pattern only matches against the URL-path, so you need the preceding RewriteCond directive in order to match the query string portion of the URL.

If the /121212/8989/ part always consists of 6 digits and 4 digits then you can be more restrictive in the regex. ie. (\d{6}/\d{4}). Likewise, if the uri parameter value consists of a limited subset of characters – perhaps a single path segment – then again this can be made more restrictive.

%1 is a backreference to the captured subpattern in the preceding RewriteCond directive, ie. the value of the uri URL parameter.

$1 is a backreference to captured group in the RewriteRule pattern, eg. 121212/8989 in your example URL.

The NE (noescape) flag is required to prevent the # being URL encoded in the response (and being seen as part of the URL-path).

The QSD (Query String Discard) flag (Apache 2.4+) is required to remove the query string from the redirected URL, otherwise the query string from the requested URL is copied as-is onto the end of the substitution. If you are still on Apache 2.2 then you can append a ? to the end of the substitution instead (essentially appending an empty query string).

This is a temporary (302) redirect.

UPDATE: This will only work if 121212 but what if it’s alpha-numeric (abc121212)

To allow a-z (lowercase) and digits then you would need to modify the RewriteRule pattern to ^nextgen-share/([0-9a-z]+/[0-9a-z]+)/full$. If you need to allow uppercase letters as well then change [0-9a-z] to [0-9a-zA-Z]. You could also use the \w “word characters” shorthand character class here instead, which is the same as [0-9a-zA-Z_] – note the additional _ (underscore).

So, this becomes:

RewriteCond %{QUERY_STRING} ^uri=(/[^&]+)
RewriteRule ^nextgen-share/(\w+/\w+)/full$ %1#gallery/$1 [QSD,NE,R,L]