Permalink Normalization with regexp


(Olivier Baillon) #1

Hi everybody,

I just install a discourse forum migrated from Kunena.

My old URL was like that :

/forum/category-name/{post_id}-title.html
example : /forum/cooking/4963-make-a-good-pizza

I insert into permalinks table this row with url = forum/old/4963 and with the good imported post_id

Now i’am trying to write the regexp in Permalink Normalization.

I tried those :
/forum/[^/]*/([0-9]+)./forum/old/\1
/forum/./([0-9]+)./forum/old/\1

but none works :confused:
I got a 404 every time

I need your help.
Thanks you very much


(Dean Taylor) #2

I’m unsure if the substitution needs escaping for this setting.

It’s most likely either:
/\/forum\/[^\/]+\/(\d+)-.*//forum/old/\1

Or if substitution needs escaping then:
/\/forum\/[^\/]+\/(\d+)-.*/\/forum\/old\/\1

Where the regular expression is commented as follows:

# /forum/[^/]+/(\d+)-.*
# 
# 
# Match the character string “/forum/” literally (case sensitive) «/forum/»
# Match any character that is NOT a “/” «[^/]+»
#    Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
# Match the character “/” literally «/»
# Match the regex below and capture its match into backreference number 1 «(\d+)»
#    Match a single character that is a “digit” (ASCII 0–9 only) «\d+»
#       Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
# Match the character “-” literally «-»
# Match any single character that is NOT a line break character (line feed) «.*»
#    Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»

(Olivier Baillon) #3

Thanks you very much Dean !
With your explanation and some little changes, it’s work !

The final regexp for my configuration :

/forum\/[^\/]+\/(\d+)-.*/forum/old/\1