Last active
December 28, 2015 09:39
-
-
Save kamiyam/7481094 to your computer and use it in GitHub Desktop.
When access WordPress default permalink, 301 redirect to 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
//for wordpress permalink import articles | |
function redirect301 ( req, res, next ){ | |
// console.log("access to: " + req.headers.host); | |
if ( req.query["p"] || req.query["page"] ){ | |
var redirect = "http://" + req.headers.host; | |
if ( req.query["p"] ){ | |
redirect += "/p" + req.query["p"] + ""; | |
} else if( req.query["page"] ){ | |
redirect += "/page" + req.query["page"] + ""; | |
} | |
// console.log("301 redirect: " + redirect + req.headers.url + "=>" + redirect ); | |
res.writeHead(301, {"Location": redirect, 'Expires': (new Date).toGMTString()}); | |
res.end(); | |
} else { | |
next(); | |
} | |
} | |
// Expose the promise we will resolve after our pre-loading | |
ghost.loaded = loading.promise; | |
when(ghost.init()).then(function () { | |
return helpers.loadCoreHelpers(ghost); | |
}).then(function () { | |
// ##Configuration | |
var oneYear = 31536000000; | |
// Logging configuration | |
if (server.get('env') !== 'development') { | |
server.use(express.logger()); | |
} else { | |
server.use(express.logger('dev')); | |
} | |
//for WordPress permalink | |
server.use( redirect301 ); | |
// Favicon | |
server.use(express.favicon(__dirname + '/shared/favicon.ico')); | |
//....... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment