Forum Moderators: phranque
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!
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.