marty90 marty90 - 4 months ago 20
Apache Configuration Question

redirect from subfolder to main folder and multiple pages to one page

We have a new website, build in WordPress. It will be replacing the old website, which was build on a custom CMS.

The old site is using this structure > for most of the content pages. On the new site we will be using
We also combined a couple of very short content pages into 1. e.g. and are now on

The issue with the folder I can resolve by using:

RewriteEngine on
RewriteRule ^content/(.*)$ /$1 [R=301,L]

This will get all the urls redirected without /content/ in betweeen the main folder and the page title.

But now I'm stuck on redirecting the other pages to the new ones.
I read somewere that the 'L' in [R=301,L] prevents further redirects, so I tried to remove that. But no luck.

RewriteRule ^content/subject1 /subjectboth [R=301]

Will not work, and:

RewriteRule ^/subject1 /subjectboth [R=301]

Will not work as well.


Problem seems to be in your reegx for matching 2nd rule.

This should work for you:

RewriteEngine on

# match /subject1 or /subject2 and redirect them to /subjectboth
RewriteRule (^|/)(subject1|subject2) /subjectboth [R=301,L,NC,NE]

# otherwise remove /content/ from start of URLs
RewriteRule ^content/(.*)$ /$1 [R=301,L,NC,NE]