Remap Rules cheat sheet


(Greg Roberts) #1

Hi,

I’m looking to use the new Remap Rules functionality and getting a little stuck. Turns out it requires the use of PCRE functions and delimeters. Not being familiar with these, and not finding a lot of support online (from either Squiz manuals or other sources), I’m wondering if anyone can shed some light on how these work.

This is the scenario I’m currently dealing with
Anything with ‘/graduate-program/’ in the URL, redirect to https://mysitehere.com.au/graduateprogram

Every combination of strings I’ve tried seems to have no impact. Does anyone have a cheat sheet / dummies guide, or at least a solution to the problem above?


(Marcus Fong) #2

The Remap Rules functionality fundamentally uses the PHP preg_replace() function, whose usage is described here:

http://php.net/manual/en/function.preg-replace.php

So essentially, “Remap From” is $pattern, “Remap To” is $replacement, and the URL is $subject when reading the PHP documentation.

Also note that for the purposes of remap rules the URL is without the leading http:// or https:// - remap rules always preserve the original protocol, you can’t modify it.

At any rate, I think what you want is something like this:

Remap From: |.*/graduate-program/.*|i
Remap To:   mysitehere.com.au/graduateprogram

The regular expression pattern breaks down as follows:

  • The | characters are the regular expression delimiters (usually / is used for this, but in this case you want to match against / characters so it’s less messy to use something else).
  • The i at the end is for case-insensitive matching (assuming that’s what you want - i.e. it’ll catch /Graduate-Program/ as well as /graduate-program/)
  • The two occurrences of .* match anything before and after /graduate-program/. This is necessary because otherwise it’ll only replace the /graduate-program/ part of the URL, instead of changing the entire URL.

Redirect Page - case sensitive