Created
April 29, 2014 14:30
-
-
Save joeyblake/11402110 to your computer and use it in GitHub Desktop.
Redirect all subdomains to main domain: ExpressJS/Ghost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* redirect all subdomains example | |
* example domain name testsite.com | |
*/ | |
// split the incoming host to get the first element | |
var incoming = req.headers.host.split('.')[0]; | |
// check if it matches your domain | |
if ( incoming !== 'testsite' ) { | |
// if it doesn't match, strip the subdomain and redirect | |
res.redirect(301, 'http://testsite.com' + req.url); | |
} else { | |
next(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment