Score:0

How can the Apache httpd root path be rewritten to a subdirectory?

gb flag

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.

Score:0
gb flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.