NullBy7e
NullBy7e

Reputation: 546

Javascript RegExp in htaccess

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

Upvotes: 0

Views: 54

Answers (1)

anubhava
anubhava

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]

Reference: Apache mod_rewrite Introduction

Upvotes: 1

Related Questions