Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Short answer: You cannot change Apache’s server-wide DocumentRoot directive from an .htaccess file. You can, however, use mod_rewrite in .htaccess to route requests into a subdirectory, so a site stored in /app can respond to requests received at the current document root. If you control the virtual-host or main Apache configuration and the content really belongs in a different directory, changing DocumentRoot there is the cleaner solution.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
The distinction matters: a rewrite changes how a request is mapped, while DocumentRoot changes the filesystem directory Apache serves by default. The examples below show when an .htaccess workaround is appropriate, how to write the rules correctly, and why a rule can appear to do nothing.
As an Amazon Associate I earn from qualifying purchases.
Free tools Windows power users keep installed
One-click scans. No signup required.
What “document root” means in Apache
Apache’s DocumentRoot is a server or virtual-host setting. It defines the base directory used to locate files for URL paths. If the root is /var/www/site, a request for /images/logo.png is normally looked up under /var/www/site/images/logo.png.
An .htaccess file is different. It is a per-directory override file read only when Apache has been configured to allow it. Its directives can alter request processing in that directory, including URL rewriting with mod_rewrite. It does not replace the virtual host’s DocumentRoot value, move files, or change the directory Apache considers the root for other virtual hosts.
#1 Best Overall
That leads to two separate solutions:
- Change the real root: edit the virtual-host or main Apache configuration, then reload Apache. This is preferable when all site content has genuinely moved to a new directory and you have server access.
- Route requests: leave the configured root in place and add rewrite rules in that root’s
.htaccessfile. This is useful on shared hosting or when a directory-based application must answer requests without changing server configuration.
A rewrite can be internal, keeping the browser’s address unchanged, or it can send a redirect, which changes the visible URL. Most “point the domain at a subfolder” requests need an internal rewrite rather than a redirect.
Choose the right approach before writing a rule
| Approach | Where it is configured | Does the browser URL change? | Does the filesystem root change? | Best use | Main concern |
|---|---|---|---|---|---|
Change DocumentRoot |
Virtual-host or main Apache configuration | No | Yes | The site has actually moved and you control Apache | Requires configuration access and an Apache reload |
Internal rewrite in .htaccess |
Current document-root directory | Usually no | No | Shared hosting or a subdirectory application | Incorrect paths can create loops or broken asset URLs |
| External redirect | .htaccess or server configuration |
Yes | No | When users should see a new URL such as /app/ |
Changes bookmarks, canonical URLs, and relative-link behavior |
Alias plus rewrite rules |
Server or virtual-host configuration | Usually no | No | Mapping a URL prefix to a directory outside the root | Needs server configuration access; relative substitutions may need RewriteBase |
If the content is all in the new directory and you can edit the virtual host, Apache’s own guidance is to change DocumentRoot or move the content rather than preserving a rewrite workaround. Rewriting is a routing technique, not a replacement for a correctly configured root.
Recommended Free Tools
Prerequisites for an .htaccess rewrite
A rule is evaluated only if Apache permits it and the rewrite module is available. Confirm these requirements before debugging the expression itself.
Put the file in the active root
The file must be named exactly .htaccess and placed in the directory Apache is actually serving. If the virtual host serves /var/www/htdocs, the relevant file is /var/www/htdocs/.htaccess. Placing it in the intended destination directory does not make it control requests that are handled by a different parent directory.
Allow rewrite directives
The directory configuration must permit at least the FileInfo override class:
<Directory "/var/www/htdocs">
AllowOverride FileInfo
</Directory>
AllowOverride All also permits the directives, but granting only the classes required by the site is more controlled. Without AllowOverride FileInfo (or AllowOverride All), rewrite directives in .htaccess are silently ignored.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Rank #2
- Used Book in Good Condition
Make sure mod_rewrite is loaded
RewriteEngine, RewriteCond, RewriteRule, and RewriteBase are provided by mod_rewrite. If the module is not loaded, Apache will report an invalid directive rather than process the rule. On managed hosting, the provider may control module loading.
Meet per-directory link requirements
Per-directory rewriting also requires either Options FollowSymLinks or Options SymLinksIfOwnerMatch, subject to the host’s policy. Do not add an option that your provider disallows; ask the administrator to enable the permitted setting in the directory configuration when necessary.
Point the current root at a subdirectory
Suppose Apache’s configured root contains an app directory, and you want requests handled from that directory without changing the visible host name. A basic pattern supplied by Apache documentation is:
RewriteEngine On
RewriteRule ^app(?:/(.*))?$ app/$1 [L]
Place this in the .htaccess file in the current document-root directory. The expression matches app and paths below it, then maps them to the corresponding path inside the app directory.
There is an important context rule: in an .htaccess file Apache removes the directory prefix before matching. Consequently, the pattern must not begin with a slash. ^/app will not match in this context; use ^app instead.
Understand what this example does
- The first
appis matched against the URL-path portion visible to the per-directory rule. (?:/(.*))?makes the remainder optional, so both the directory path and a path beneath it can be handled.app/$1is the relative substitution that points into the subdirectory.[L]tells the current rewrite pass to stop after this rule.
Test the mapping with an actual file and a nested path. If the application is meant to answer requests at the site root rather than under /app/, use a root-to-subdirectory rule designed for that URL shape instead of blindly adapting this example. A rule that repeatedly rewrites an already rewritten path can produce an internal redirect loop, so inspect the logs whenever the response becomes a 500 error.
Use the correct pattern for a front-controller application
Many PHP and other web applications send every request that is not a real file or directory to one entry point such as index.php. For an application installed in a subdirectory, Apache documents this per-directory pattern:
RewriteEngine On
RewriteBase /myapp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
How the conditions protect assets
%{REQUEST_FILENAME} represents the filesystem path Apache has resolved for the current request. The !-f condition allows an existing file, such as a stylesheet or image, to be served normally. The !-d condition does the same for an existing directory. Only requests that are neither real files nor real directories are sent to index.php.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesWhy the application prefix matters
The value in RewriteBase is the URL prefix for the application in this example. The rule itself is written without a leading slash because it runs in per-directory context. Adjust both the directory placement and URL prefix to match the application’s actual installation.
Apache notes that FallbackResource can be simpler and more efficient for this particular front-controller use case. It is worth considering when the application needs a straightforward fallback and does not require the conditional rewrite logic above.
Understand RewriteBase before adding it
RewriteBase supplies the URL prefix Apache uses when it turns a relative substitution back into a URL path. It matters when the URL path and filesystem path do not line up, such as with an Alias, a symlink mapping, or another boundary between URL space and filesystem space.
It is not a universal fix for a failed rule. If the URL and filesystem paths already correspond, adding a guessed base can make the result harder to understand. Absolute URL-path or full-URI substitutions do not use RewriteBase.
Rank #4
Decide whether the paths differ
- Write down the URL the visitor requests, for example
/myapp/orders/7. - Write down the filesystem directory Apache must use, for example a directory represented by an alias rather than a child of the current root.
- If those paths share the same per-directory relationship, start without
RewriteBase. - If a relative substitution crosses the mapping boundary, set
RewriteBaseto the URL prefix that represents the target directory.
Do not use a leading slash in the RewriteRule pattern simply because RewriteBase contains one. They serve different purposes.
Internal rewrite versus redirect
Internal rewrite
An internal rewrite changes Apache’s lookup while leaving the address bar unchanged. It is appropriate when the public URL should remain stable but the files live below a subdirectory. Because the browser does not see the internal path, application links, cookies, and canonical URLs must still be configured for the public URL you intend to expose.
External redirect
A redirect tells the browser to request another URL. Use one when the subdirectory should be visible, such as moving visitors from the root to /app/. The visible URL changes, so update links, bookmarks, canonical metadata, and any path-sensitive application settings accordingly.
Do not add a redirect merely because an internal rewrite feels less intuitive. Redirecting a request to the same path that a rule is already processing can create a loop, and redirecting every asset request to a directory index can break the site.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Why a RewriteRule appears to do nothing
Work through these checks in order. Each one corresponds to a common failure mode in per-directory rewriting.
1. Verify the active directory
Confirm which virtual host answered the request and which directory it serves. An .htaccess file in an unused project directory has no effect on another virtual host. Check the host’s configuration or ask the administrator for the active root.
Best Value
- Used Book in Good Condition
2. Check AllowOverride
Ask for the <Directory> block governing that root and confirm it has AllowOverride FileInfo or AllowOverride All. If overrides are disabled, Apache ignores rewrite directives instead of partially applying them.
3. Confirm mod_rewrite
Make sure the server has loaded mod_rewrite. A missing module commonly produces an “Invalid command” error for RewriteEngine; a host may need to enable it centrally.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 114. Remove the leading slash from the pattern
In .htaccess context, use:
RewriteRule ^app/(.*)$ app/$1 [L]
not:
RewriteRule ^/app/(.*)$ app/$1 [L]
Apache strips the directory prefix before matching, so a pattern beginning with ^/ never matches there.
5. Check the substitution and base
Determine whether the substitution is relative to the current directory and whether the URL-to-filesystem mapping includes an alias or symlink. Add or correct RewriteBase only when that mapping requires it. An incorrect base can send Apache to a path that does not exist.
6. Look for loops and forbidden processing
Inspect Apache’s error log after reproducing the request. Repeated internal redirects usually mean the rule matches its own rewritten result or a separate rule sends the request back. A forbidden rewrite error can indicate that the server’s override or symlink policy does not permit the requested operation.
7. Test one request at a time
Start with a known static file, then test a nested path, then test the application’s front controller. Clear any browser cache only after the server-side mapping is correct; caching can conceal whether the newest rule ran.
Common mistakes and their corrections
| Symptom | Likely cause | Correction |
|---|---|---|
| The rule never matches | The pattern starts with ^/ |
Remove the leading slash in the RewriteRule pattern. |
| Every request returns the old site | The file is not in the active document root, or overrides are disabled | Verify the serving directory and AllowOverride. |
| Images and CSS fail | Requests for real assets are being sent to the front controller | Preserve existing files and directories with !-f and !-d conditions. |
| Apache reports an internal redirect loop | The substitution matches the rule again, or two rules point at each other | Inspect the rewritten path, narrow the pattern, and review the error log. |
| Relative links point to the wrong location | The public URL prefix and filesystem path differ | Review the application’s base URL and use RewriteBase only where the mapping requires it. |
| Apache returns a 500 error after editing | Invalid directive, unavailable module, or disallowed option | Read the error log, validate the directive spelling, and have the administrator check module and override settings. |
When changing DocumentRoot is the better fix
Use the server configuration when the new directory is the site’s real home, not merely an implementation detail. A direct root change avoids an extra rewrite pass, reduces the chance of relative-path mistakes, and makes the virtual host’s intent explicit. It also prevents unrelated directories under the old root from being accidentally exposed through broad rules.
The trade-off is access and coordination. You need permission to edit the virtual-host or main Apache configuration, and the change normally requires a reload or restart according to the host’s operating procedure. On shared hosting, those controls are often unavailable; in that case, a carefully scoped .htaccess rewrite may be the only practical option.
Use this decision checklist
- Choose DocumentRoot when all content belongs in the destination directory and you control Apache’s virtual-host configuration.
- Choose an internal rewrite when the public URL must stay the same, the application is below the current root, or hosting permits only
.htaccess. - Choose a redirect when the destination prefix should be visible to visitors.
- Choose an Alias with server configuration when a URL must map to a directory outside the normal root.
- Use a front-controller rule when only non-file and non-directory requests should reach an application entry point.
A safe rollout procedure
- Back up the existing file. Save the current
.htaccessbefore adding rules so you can restore a known-good version. - Map the paths. Record the public URL, current document-root directory, destination directory, and application entry point.
- Confirm server prerequisites. Check
AllowOverride,mod_rewrite, and the permitted symlink option. - Add the smallest rule that fits. Do not combine a subdirectory mapping, redirect, and front-controller fallback until each works independently.
- Test static content first. Request a real file and verify that it is served from the intended directory.
- Test an application route. Request a nested, non-file URL and confirm that the correct entry point handles it.
- Inspect logs immediately. Resolve loops, forbidden processing, and missing-file errors before adding more conditions.
- Document the public path. Tell the application which URL prefix it should generate for links, forms, cookies, and redirects.
Keep the final rules narrow and comment why the mapping exists. A later administrator should be able to distinguish an intentional subdirectory route from an obsolete migration rule.
Quick Recap
Key points to remember
.htaccesscannot redefine Apache’s server-wideDocumentRoot.mod_rewritecan route requests into a subdirectory without changing the browser URL.- Per-directory patterns omit the leading slash because Apache strips the directory prefix before matching.
AllowOverride FileInfoorAllowOverride Allis required for rewrite directives in.htaccess.RewriteBaseis for relative substitutions when URL and filesystem paths differ, particularly across aliases or symlink mappings.- If the content truly belongs in a new root and you control Apache, change
DocumentRootdirectly instead of preserving a rewrite workaround.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




