if else .htaccess/ISAPI

Question!

I would like to check a URL to see if it contains one of multiple strings, and then based on that, send it to a different URL. Am I forced to use multiple lines, one for each possibility? Or is there anyway to form an if statement? I figured that something like this should work:

(string1)(string2)(string3) example.com/$1$2$3

because in my case, multiple strings will never be found, so the extra strings will be NULL in the redirected URL. however, that only works if I want to use the string itself as the modified part of the new URL, which I do not.

At what file size do I need to start worrying about my file load time?

Any ideas?

Thanks!



Answers

You'd probably want something more like this:

RewriteRule string1|string2|string3 example.com/$0

The expression string1|string2|string3 in the regex matches any of the three alternatives, and $0 is of course replaced with whatever the entire regular expression matched.

By : David Z


You can use simple alternation in your regular expression:

RewriteRule ^/(string1|string2|string3)$ http://example.com/$1

This would match the paths /string1, /string2 or /string3.

By : Gumbo


This video can help you solving your question :)
By: admin