× Here you can get community support related to ReDJ.

section/cat/254-a-name to section/cat/a-name

More
7 years 7 months ago #6077 by Stef
Hi,
Here's the URL with which one a get a 404 :
www.mysite.com/section/category/232-a-name
And that's where I have to redirect it :
www.mysite.com/section/category/a-name
(it is also true for www.mysite.com/section/anothercategory/subcategory/527-a-anothername
So actually, I just have to remove the ID (232 or 527) and the dash (-) to have my URL working.
So I have thought about something like this :

From URL :
^/section/{path}/{query}
To URL :
{scheme}://{siteurl}/section/{path}/??

Of course, the "??" is because I just don't know what to write here... Any suggestion ?

Please Log in or Create an account to join the conversation.

More
7 years 7 months ago - 7 years 7 months ago #6078 by Stef
I have found this www.selfget.com/forum/redj/1231-replacing-item-1234.html#5002
and tried this :

From URL :
^/section/
To URL:
{scheme}://{siteurl}{path}/{preg_match 1}/[0-9]+-(.*)$/{/preg_match}

And that gave me a
www.mysite.com/section/category/232-a-name/a-name/a-name/a-name/∞
I think the /232-a-name is included in the {path}, but I can't find out how to remove it.

For example, I tried a :
{scheme}://{siteurl}/section/{pathrtrim [0-9]+-(.*)}/{preg_match 1}/[0-9]+-(.*)$/{/preg_match}
But it didn't give any result.

And for the loops at the end, I just can't see.
Any suggestion ?
Last edit: 7 years 7 months ago by Stef.

Please Log in or Create an account to join the conversation.

More
7 years 7 months ago #6080 by admin
Try this:
From URL: ^/section/category/[0-9]+-
To URL: {scheme}://{siteurl}/section/category/{preg_match 1}/\/section\/category\/[0-9]+-([^\/]+)/{/preg_match}
Request only: true (checked)

Note: Macro preg_match works only for Enterprise version.

Kind regards,
Luigi

Please Log in or Create an account to join the conversation.

More
7 years 7 months ago #6081 by admin
This will work also for www.mysite.com/section/anothercategory/subcategory/527-a-anothername:
From URL: ^/section/
To URL: {scheme}://{siteurl}/section/${a}/${b}
Request only: true (checked)
Placeholders:
a={preg_match 1}/\/section\/(.*)\/[0-9]+-([^\/\?]+)/{/preg_match}
b={preg_match 2}/\/section\/(.*)\/[0-9]+-([^\/\?]+)/{/preg_match}

Kind regards,
Luigi
The following user(s) said Thank You: Stef

Please Log in or Create an account to join the conversation.

More
7 years 7 months ago - 7 years 7 months ago #6082 by Stef
Hi Luigi,
Thanks for the 'How to'.
A made some changes to fit my needs...

From URL
I added some regex to be sure that the redirection will apply on items and not list views (/section - section/category - section/category/subcategory are Search & List view from Seblod). So it give :
\/section\/(.*)\/([0-9]{1,3}-.*)
It works well - I'm just not sure if it is the simplest way...
BTW, I found a really good tool to help who like me are just discovering regex :
regex101.com
Really helpful to see what the regex is actually selecting in your string with clear explanation. 2 Thumbs Up for this one :-)
Last edit: 7 years 7 months ago by Stef.

Please Log in or Create an account to join the conversation.

More
7 years 7 months ago #6083 by admin
Hi Stef,
thank you for reporting, I am glad it worked.

Best regards,
Luigi

Please Log in or Create an account to join the conversation.

Time to create page: 0.144 seconds