Jan Pulpán Jan Pulpán - 2 months ago 17
Apache Configuration Question

Htaccess redirect internal error

I need to create a

.htaccess
redirect that if the user enters the URL
www.olddomain.com/bonus
redirect them to
www.newdomain.com/bonus
and any other pages or root of the old domain to
www.newdomain.com
.

For some time I have been using this code to achieve it

RedirectMatch 301 ^/bonus/ http://www.newdomain.com/bonus/ [L]
RedirectMatch 301 ^/ http://www.newdomain.com/ [L]


But since last week it just causes an Internal Server Error.

I have figured out that the error is caused by the
[L]
on each line. If I remove it I get no error, but the user is alway redirected to
www.newdomain.com
even if he goes to
www.olddomain.com/bonus
.

How can I solve this problem?

Answer
RedirectMatch 301 ^/bonus/ http://www.newdomain.com/bonus/ [L]
RedirectMatch 301 ^/ http://www.newdomain.com/ [L]

These directives would never have worked, so it's hard to say why you are suddenly getting the error.

As you suggest the [L] flag is what's causing the 500 Internal Server error. This is invalid syntax - but this has always been invalid syntax!? RedirectMatch is a mod_alias directive. Whereas, trailing flags (such as [L]), are a mod_rewrite (ie. RewriteRule) feature.

even if he goes to www.olddomain.com/bonus

But neither will those directives redirect the above URL. It will only redirect www.olddomain.com/bonus/ (with a trailing slash). If you need to match the above URL then you need to remove the trailing slash from the directive. For example:

RedirectMatch 301 ^/bonus http://www.newdomain.com/bonus
RedirectMatch 301 ^/ http://www.newdomain.com/