我在Javascript中有以下RegEx:
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];
我在这里尝试的是短代码,我希望将/ ~Xx0X0等任何网址重定向到/create.html。 其中X / x是非空白字符,0是数字。
我如何在.htaccess mod_rewrite中使用正则表达式? 我希望我能正确解释这一切。
短代码格式
〜
大写字符
小写字符
位
大写字符
位
答案 0 :(得分:1)
您可以将此代码放在DOCUMENT_ROOT/.htaccess
文件中:
RewriteEngine On
RewriteBase /
RewriteRule ^~[A-Z][a-z][0-9][A-Z][0-9]$ /create.html [L,R=301]