0

While I have seen similar questions elsewhere, some of those questions ask about redirecting the exact root path or else the provided answers don’t always work properly.

What I require is to rewrite all paths starting from the root to a subdirectory of the document root.

One of the possible solutions is to simply change the document root. However, depending on how you have configured your vhosts or written other rules, this may not always be the best option.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
dVVIIb
  • 1
  • 2

1 Answers1

0

This may be done in different ways. Here is one simple approach using mod_rewrite.

Update:

This allows for cases where additional directories under root need to be excluded, such as phpMyAdmin. In such cases and some others, using a Last [L] rule is problematic. Add your required exclusions in place of phpMyAdmin, separated by pipes: '|'.

RewriteEngine on
RewriteRule ^/(?!phpMyAdmin|mydir).* /mydir$0 [NE]

Previous Solution:

RewriteEngine on
RewriteRule /mydir.* $0 [L]
RewriteRule /.* /mydir$0 [NE]

Note that while I have seen some try to use a single rule rewrite, I believe the middle line is necessary to prevent recursion.

dVVIIb
  • 1
  • 2