Skip to content

Instantly share code, notes, and snippets.

@pirtleshell
Created October 28, 2016 19:49
Show Gist options
  • Save pirtleshell/9bc360879fcacfa43d2de750d5e6e62f to your computer and use it in GitHub Desktop.
Save pirtleshell/9bc360879fcacfa43d2de750d5e6e62f to your computer and use it in GitHub Desktop.
Move web root (document root) of a server to a subdirectory on Apache using .htaccess
# I had such a hard time finding this information, so I decided to keep it here.
# Change your server's pointing "example.com" from "/public_html/" to "/public_html/subdir" **without** changing the URL!
# URL remains the same, server directory changes
# Replace "example.com" with your domain and "subdir" with the directory your site is in.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteRule ^(.*)$ /subdir/$1 [L]
</IfModule>
# For example, the URL "example.com/magical-dinosaur/" will remain the same.
# But your server will load "/public_html/subdir/magical-dinosaur/" as opposed to "/public_html/magical-dinosaur/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment