Reputation: 300
I have the following URL on my site that inadvertently got indexed while doing some site testing. I am trying to redirect the URLs to the correct page on my site. For whatever reason I can't get the redirect to actually work as intended.
Here is the URL indexed on my site
domain.com/wa/-county/communityname
Sometimes a community is actually a city and needs to be redirected. The URL should actually be redirected to:
domain.com/wa/cityname
For those instances where a community is actually a city.
Now here is the the part that is throwing a wrench in my works I believe.
/-county/
needs to explicitly match that text. I do have some URL instances on the site where the structure is:
domain.com/wa/king-county/selah
The URLs are generated dynamically. The Itemid of the site is what causes the county name king
in this case to be generated. The indexed URLs just got indexed without the county name portion of the URL.
Here is the regex and redirectmatch I have tried so far.
RedirectMatch 301 (\/-county\/)(.+$) /wa/$2
Now the way I understand this is
(.*$) = $2
Can anyone shed any additional light on this subject for me?
Here is a link to the Regex101 Test
Upvotes: 1
Views: 304
Reputation: 784898
You can use this rule as your very first rule site root .htaccess:
RedirectMatch 301 ^/([\w-]+)/-county/(.+)$ /$1/$2
Make sure to clear your browser cache when testing this change.
Upvotes: 2