You can use this rule in site root .htaccess:
RewriteEngine On # add a trailing slash if test/$1 is a directory RewriteCond %{DOCUMENT_ROOT}/test/$1 -d RewriteRule ^(.*[^/])$ %{REQUEST_URI}/ [L,R=301,NE] RewriteRule ^(?!test/)(.*)$ test/$1 [L,NC] (?!test/) is negative lookahead to skip rewrite when request is already starting with /test/