marty90 marty90 - 1 month ago 6
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 > domain.nl/content/page-title for most of the content pages. On the new site we will be using domain.nl/page-title.
We also combined a couple of very short content pages into 1. e.g. domain.nl/pageaboutsubject1 and domain.nl/pageaboutsubject2 are now on domain.nl/pageboutboth

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.
Adding:

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


Will not work, and:

RewriteRule ^/subject1 /subjectboth [R=301]


Will not work as well.

Answer

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]

References: