Skip to main content
added 82 characters in body
Source Link
anubhava
  • 790.3k
  • 67
  • 603
  • 671

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] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(?!test/)(.*)$ test/$1 [L,NC] 

(?!test/) is negative lookahead to skip rewrite when request is already starting with /test/

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/

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] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(?!test/)(.*)$ test/$1 [L,NC] 

(?!test/) is negative lookahead to skip rewrite when request is already starting with /test/

added 160 characters in body
Source Link
anubhava
  • 790.3k
  • 67
  • 603
  • 671

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/

You can use this rule in site root .htaccess:

RewriteEngine On RewriteRule ^(?!test/)(.*)$ test/$1 [L,NC] 

(?!test/) is negative lookahead to skip rewrite when request is already starting with /test/

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/

Source Link
anubhava
  • 790.3k
  • 67
  • 603
  • 671

You can use this rule in site root .htaccess:

RewriteEngine On RewriteRule ^(?!test/)(.*)$ test/$1 [L,NC] 

(?!test/) is negative lookahead to skip rewrite when request is already starting with /test/