I am attempting to create some 301 redirects using .htaccess in order to fix some Crawler Errors that Google is encountering. Google is using old versions of some of my URLs, which is causing errors to arise when the spider attempts to access the legacy paths. These legacy URLs contain spaces, and there were many of them, all appearing at different places within the URL string. For instance, a URL might have looked like this:
http://www.example.com/car-kits-halogen-aircon-oil/773 CAR 773-halogen-aircon-oil
These URLs are needlessly long, especially since they ultimately all displayed identical content. They have now been shortened to something like this:
http://www.example.com/773-halogen-aircon-oil
There are literally over 1,000 of these, although there are only 6 permutations of the end of the URL, so I thought I could use either RedirectMatch or RewriteRule to easily match whether one of those 6 permutations existed and redirect to the appropriate new URL. I have tried the following:
RedirectMatch .*/773[\s]?(%20)?CAR[\s]?(%20)?773-halogen-aircon-oil$ http://www.example.com/773-halogen-aircon-oil
as well as:
RewriteEngine On
RewriteBase /
RewriteRule .*/773[\s]?(%20)?CAR[\s]?(%20)?773-halogen-aircon-oil$ http://www.example.com/773-halogen-aircon-oil [R=301,L]
These are not working. I have tried many different options, including escaping the spaces with a \ instead of the regex character class, changing the beginning of the regex to ^.*/?773 and many other things, but nothing works.
I have used the regex test feature at http://www.regular-expressions.info/javascriptexample.html and it reports that my regular expression is valid and generates a match against the URLs I expect it to, but .htaccess is not redirecting as I expect.
I can use a plain Redirect as follows:
Redirect 301 "/car-kits-halogen-aircon-oil/773 CAR 773-halogen-aircon-oil" http://www.example.com/773-halogen-aircon-oil
This works, but it is problematic, because it matches only when car-kits-halogen-aircon-oil is present, and there are probably 200 permutations of that URI segment, which would make manually entering every possible permutation a huge undertaking.
Any suggestions? Is what I am trying to do even possible?