titanas
Member
Posted 10 months ago #
Hey,
How to redirect something like /ab/ab/ab/ab => ab ?
ab is actually a WordPress slug something like /wordpress-is-awesome/ so the actual problematic slug looks like this: /wordpress-is-awesome/wordpress-is-awesome/wordpress-is-awesome/wordpress-is-awesome/ and want to be redicted to /wordpress-is-awesome/ only
A solution like (.*)/(.*)/(.*)/(.*) => $1 dosen't make sense because it conflicts with stuff like /tag/help/page/3
Any ideas?
You'll need to be more specific with your regex so it only matches the exact URL you want to redirect. Also, you can use ^ and $ to match only the start and end of a URL.
titanas
Member
Posted 10 months ago #
Thank for the reply.. that's the thing, i don't know how to be more specific. Can you help in an example like /wordpress-is-awesome/wordpress-is-awesome/wordpress-is-awesome/wordpress-is-awesome/ ?
I'll play with ^ and $ and see what happens.
Something like this would not match any other URLs:
^/wordpress-is-awesome/.*
If you only have the one URL to match then there is no need to use a regex - just match the entire URL.
titanas
Member
Posted 10 months ago #
It's different URLs all the time following the same pattern... so it's ^/.*/.* or not? :)
Then it looks like unless you can find a way to uniquely describe the URLs there is no single pattern that will fit. A regex is powerful but it won't fit all situations.
titanas
Member
Posted 10 months ago #
Titanas,
There is actually a way to do exactly what you want with regular expressions, though by the looks of the above thread, it is a lesser known feature:
Source URL: ^(/[a-z0-9-]+){\1}+[/]?$
Target URL: $1
Explanation:
() the regex remembers what is between brackets. With \1 you have the regex recall the remembered string and match that again one or more times - in this case '/wordpress-is-awesome' -. I put the \1 between {} to avoid the regex confusing it with a literal pattern.
In the target use $1 as the starting / is already included in the match.
Hope this helps!
Smile,
Juliette