here is the regex redirect rule you can use in Yoast SEO’s redirect manager to redirect URLs like /t/mytag
to /tag/mytag
.
In Yoast SEO Redirects:
- Go to SEO -> Redirects.
- Click on Add new redirect.
- In the “Origin URL” field, enter:
Code snippet
^/t/(.*)$
- Make sure the “Regex” checkbox (or similar option indicating regex) for the Origin URL is checked.
- In the “Redirect to URL” field, enter:
/tag/$1
- Choose the desired redirect type (usually 301 for permanent).
- Click Add redirect.
Explanation:
^
: Matches the beginning of the URL path./t/
: Matches the literal characters/t/
.(.*)
: This is a capturing group..
: Matches any character (except newline).*
: Matches the previous character (.
) zero or more times. So,.*
matches everything after/t/
.()
: The parentheses capture the matched content (everything after /t/
) so it can be used in the destination.
$
: Matches the end of the URL path. This ensures it only matches paths that exactly start with/t/
and contain nothing else before the end (preventing matching things like/t/something/else
)./tag/$1
: This is the destination URL./tag/
: The new literal path start.$1
: This is a backreference to the content captured by the first capturing group(.*)
in the Origin URL.
This rule will take whatever comes after /t/
in the original URL and place it after /tag/
in the new URL. Remember to test it after adding!