Last active
July 4, 2016 08:25
-
-
Save timneutkens/8f33fde32a8e9c3f42e3e2f193ff5c32 to your computer and use it in GitHub Desktop.
Fast way to create apache rewrite rules
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
// Create RewriteRule from given variables | |
function createRewriteString(oldUrl, newUrl, removeDomainPrefix) { | |
return 'RewriteRule ^' + oldUrl.replace(removeDomainPrefix, '') + '/?$ ' + newUrl + ' [NC,L,R=301]' | |
} | |
// Url to path mapping. Seperated by one space. | |
const urls = `http://example.com/foo/bar /bar/foo | |
http://example.com/foo/baz /baz/foo` | |
// Split by line break | |
urls.split("\n") | |
// Map through all paths | |
.map(function(paths) { | |
// Split url and path | |
const urlPaths = paths.split(" ") | |
// Create rewrite string | |
const rule = createRewriteString(urlPaths[0], urlPaths[1], 'http://example.com/') | |
// Log it to the console | |
console.log(rule) | |
return rule; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment