1
votes

First question here :).

A site we run currently uses hierarchical (nested) URLs e.g. example.com/folder/page/

We would now prefer flat URLs e.g. example.com/page/

Our CMS can easily allow a switch to pages being given flat URLs. However it does not handle the redirects from the old hierarchical URLs. It looks like it needs to be handled in the .htaccess file.

There are 250+ pages so it would be preferable to have code that would handle all the redirects rather than doing a redirect 301 for each URL.

Can anyone provide some .htaccess code or point me in the right direction to achieve the redirects?

2

2 Answers

0
votes

It's probably not the most efficient thing in the world, but I do this on my blog using a big .htaccess file containing:

RedirectMatch permanent ^/old/url http://example.com/new-url

If you can edit the main Apache config file instead of using .htaccess files, it will likely be more efficient to use Redirect instead of RedirectMatch (which is easier to use inside .htaccess files because, if I recall, it matches against the URL relative to the .htaccess file instead of… something else… when Redirect is involved. But I could be wrong about that.)

0
votes

You can try this code in your .htaccess under $DOCUMENT_ROOT:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteOptions MaxRedirects=5

RewriteRule ^folder(/page/.*)$ $1 [NC,L,R=301]