.htaccess RewriteBase equivalent for WordPress – Passing a URL as a variable without getting a 404

It wouldn’t give you exactly that format, but you could add a rewrite endpoint named slide and get the format http://www.sitename.com/gallery/slide/2/:

function wpd_add_slide_endpoint(){
    add_rewrite_endpoint( 'slide', EP_PAGES );
add_action( 'init', 'wpd_add_slide_endpoint' );

Then you could localize your script to pass the slide number, using get_query_var('slide') to fetch the current value.