Forum Moderators: phranque

Message Too Old, No Replies

RedirectMatch not working, but RewriteRule does

         

Mike521

8:33 pm on Apr 14, 2009 (gmt 0)

10+ Year Member



I have a rewrite rule that's been working for a while:

RewriteRule ^s-([^.]+).*$ merchant.mvc?Screen=SEARCH&Search=$1 [T=application/x-httpd-mvc]

This is for internal searches so a URL like example.com/s-searchText.htm works. We're switching to a new system which lives at URLs like this:

[search.example.com...]

I tried commenting out the rewrite and doing a RedirectMatch:

RedirectMatch ^s-([^.]+).*$ [search.example.com...]

but I got a 404 (seems like the redirect match didn't trigger or something). But changing the original rewrite rule actually ended up with a 302 redirect:

RewriteRule ^s-([^.]+).*$ [search.example.com...] [QSA,T=application/x-httpd-mvc]

So I have two questions that hopefully someone can help me out with:

1. why doesn't the redirectmatch work?
2. why does the rewrite end up with a 302 redirect? I expected it to fail completely (I didn't think you could do a "rewrite" to another domain/subdomain)

thanks!

g1smd

8:47 pm on Apr 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule with either a domain name in target URL, or an [R] flag, _is_ by definition a 302 redirect.

Omit the domain name, and omit the [R] flag, for a rewrite. Add [L] to the end of the rule.

A rewrite targets an internal filepath in the server. It cannot target another domain. You would use a proxy function for that.

Add both the domain name in target URL, and [R=301,L] flag, to make a 301 redirect using a RewriteRule directive.

jdMorgan

1:49 am on Apr 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) You'd need a leading slash on the RedirectMatch pattern to make it work.

Jim

Mike521

1:52 pm on Apr 15, 2009 (gmt 0)

10+ Year Member



thanks g1smd, that did the trick!

what about that redirectmatch, is there a way to get that working?

Mike521

2:56 pm on Apr 15, 2009 (gmt 0)

10+ Year Member



oh thanks jdMorgan I didn't see your response, I'll give that a shot now