[thelist] mod_rewrite redirect to external URL
Joshua Olson
joshua at waetech.com
Tue Jul 27 07:07:42 CDT 2004
> -----Original Message-----
> From: Maximillian Von Schwanekamp
> Sent: Monday, July 26, 2004 11:40 PM
>
> How can I use mod_rewrite to redirect something like this:
> /mydirectory -> http://otherdomain.com/some/arbitrary/file.htm
> /* -> http://otherdomain.com/
>
> For the first one, this works fine:
> RewriteRule ^mydirectory(.*)
> http://otherdomain.com/some/arbitrary/file.htm
>
> But I cannot seem to negate the "in all other cases" rule to work
> properly. Help?
Maximillian,
I have a bit of experience with ISAPI_ReWrite, not specifically mod_rewrite,
but perhaps the following may be helpful.
Try a negative lookahead to match anything that specifically DOESN'T start
with mydirectory. Example:
RewriteRule ^mydirectory(.*) http://otherdomain.com/some/arbitrary/file.htm
RewriteRule ^(?!mydirectory)(.*) http://otherdomain.com/
On a side note, the rule that you have already to match requests into the
folder mydirectory is a bit too greedy (it'll match mydirectory2/, for
example). You may want to consider a revision. I've had really good luck
with the following general syntax for matching strings directly to the root
of the specified folder:
^mydirectory/*(?:\?([^\?]*))?
And then the following for matching strings into the root or any subfolder
of the specified folder:
^mydirectory(?:/*|/[^\?]+)(?:\?([^\?]*))?
Please do note that the above rules extract the querystring as well so that
you can append it to the new URL if necessary.
> TIA!
HTH,
<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com/service_areas/
706.210.0168
More information about the thelist
mailing list