RewriteEngine On RewriteBase /gallery2/ RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d [OR] RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php RewriteCond %{REQUEST_URI} !/gallery2/main\.php$ RewriteRule . - [L] RewriteCond %{THE_REQUEST} /gallery2/a/*([^?]*)(\?.|\ .) RewriteCond %{REQUEST_URI} !/gallery2/main\.php$ RewriteRule . /gallery2/%1