Skip to content

Instantly share code, notes, and snippets.

@niklasravnsborg
Last active October 5, 2016 21:02
Show Gist options
  • Save niklasravnsborg/69af5553ce27d65b98f2 to your computer and use it in GitHub Desktop.
Save niklasravnsborg/69af5553ce27d65b98f2 to your computer and use it in GitHub Desktop.
one.com uses subdirectories as subdomains, here is a handy rewrite
RewriteEngine On
# redirect subdomains to matching folders
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_ADDR} !=127.0.0.1
RewriteCond %{SERVER_ADDR} !=::1
RewriteCond %{HTTP_HOST} !.*\.yourhost.com
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# redirect all other traffic to main
RewriteCond %{HTTP_HOST} ^(?:www\.|)yourhost.com
RewriteCond %{REQUEST_URI} !^/main/?
RewriteRule ^(.*)$ /main/$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment