Mobile app version of vmapp.org
Login or Join
Connie744

: Redirect multiple files using .htaccess 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

@Connie744

Posted in: #Htaccess #Redirects #Seo

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/(.*)/(.*) example.com/folder/folder//
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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Connie744

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

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/(.*) /

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme