Skip to content

Instantly share code, notes, and snippets.

@chrisjangl
Last active June 21, 2020 16:00
Show Gist options
  • Save chrisjangl/7c5df36798131d6b0ea6f0289d7031f2 to your computer and use it in GitHub Desktop.
Save chrisjangl/7c5df36798131d6b0ea6f0289d7031f2 to your computer and use it in GitHub Desktop.
.htaccess to host WordPress in a subdirectory. Some shared hosting won't let your primary domain be assigned to a subdirectory - this will help to get around that.
# replace <domainname> with your domain name
# replace <directoryname> with the name of the directory where WordPress is located
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?<domainname>.com$
RewriteCond %{REQUEST_URI} !^/<directoryname>/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /<directoryname>/$1
RewriteCond %{HTTP_HOST} ^(www.)?<domainname>.com$
RewriteRule ^(/)?$ <directoryname>/index.php [L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment