1

I have a lot of files with a lot of sub directories which I moved one folder up, so, say, instead of example.com/cdn/folder/folder/file.html, it now looks like this example.com/folder/folder/file.html.

My problem lies in SEO, I have a lot of back links which point to files which used to be in the old directory structure, and everyone who tries to access these files via those links will get a 404.

Now, I know that I can resolve the problem by adding a simple line of code in .htaccess, so I have read quite a number of tutorials on the Internet which explain how to redirect files from one place to another using wildcards and RedirectMatch techniques. I have found a site which explains how to do it, but I can't seem to get it working. I don't know what my problem is.

This is what I have come up with so far:

RedirectMatch 301 /cdn/folder/folder/(.*)/(.*) http://example.com/folder/folder/$1/$2

This, however, does not do what I want it to do. Say, if someone accesses a file via example.com/cdn/folder/folder/file.html, they will get a 404. The code above does not resolve the problem. But, it does what I want it to do only for example.com/cdn/folder. Someone trying to access the subdirectory of /cdn will be redirected to /folder.

Please point me in the right direction.

1 Answer 1

2

It would seem you don't need to worry about how many folders are nested, just whether the requested URL is contained in the /cdn folder? If it is then remove it...

RedirectMatch 301 ^/cdn/(.*) /$1
1
  • Thank you very much. I knew it was an easy fix. I guess I was overcomplicating things as usual...
    – Nick
    Nov 14, 2013 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.