2

I am trying to redirect URLs of a old Perch CMS to a custom CMS like this:

Redirect /sites/praxis/   http://example.com/_Unser_Cabinet
Redirect /sites/praxis/sites/chiropraktik   http://example.com/_Unser_Cabinet

In this case the subfolder of praxis should redirect to the same URL but instead it ends up here:

http://example.com/_Unser_Cabinet/sites/chiropraktik

and

Redirect /sites/behandlungen/   http://chirohelias.com/_Was_ist_Chiropraktik
Redirect /sites/behandlungen/sauglingekinder/  http://chirohelias.com/_Chiropraktik_fur_Neugeborene_und_Kinder

In this case the subfolder should end up at a different URL with similar results it ends up here:

http://example.com/_Was_ist_Chiropraktiksauglingekinder/

I understand that its taking the first redirect and applying it to the second URL but I cant figure out the logic to get around this.

2

The Redirect directive is designed to preserve the rest of the path across the redirect. If you don't want this behavior, you can use RedirectMatch instead which give you a lot more control:

RedirectMatch /sites/praxis.* http://example.com/_Unser_Cabinet

the .* matches any URL under that path and redirects any of them to the new URL without anything appended. If you wanted to use the path, you would need to use $1 in the final URL as a placeholder. See the documentation.

I didn't put a trailing slash on praxis/ because you probably want to redirect the URL without the trailing slash. However if you have a URL like /sites/proxisxyzzy that you don't want to redirect, you should use the slash.

Another workaround would be to reverse the order of your directives.

Redirect /sites/praxis/sites/chiropraktik   http://example.com/_Unser_Cabinet
Redirect /sites/praxis/   http://example.com/_Unser_Cabinet

The redirect directives are executed in order until one matches. When the most specific one is first, it takes precedence. The drawback to this approach is that you would have to write lots of specific rules first, followed by a general rule for the directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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