Reputation: 546
I have the following RegEx in Javascript:
var re1 = '(~)';
var re2 = '([a-z])';
var re3 = '([a-z])';
var re4 = '(\\d)';
var re5 = '([a-z])';
var re6 = '(\\d)';
var matchExp = new RegExp(re1 + re2 + re3 + re4 + re5 + re6, ["i"]);
var match = window.location.href.match(matchExp);
var shortcode = match == null ? "" : match[1];
What I am trying here is shortcodes, I want any url such as /~Xx0X0 to be redirected to /create.html. Where X/x is a non-whitespace character and 0 is a digit.
How would I use the Regex in .htaccess mod_rewrite? I hope that I explained it all correctly.
Shortcode Format
~
Uppercase Character
Lowercase Character
Digit
Uppercase Character
Digit
Upvotes: 0
Views: 54
Reputation: 785671
You can put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteBase /
RewriteRule ^~[A-Z][a-z][0-9][A-Z][0-9]$ /create.html [L,R=301]
Upvotes: 1