views:

662

answers:

4

Could someone help me translate the following pseudo-code into code understood by Helicon Tech's ISAPI_Rewrite module:

if (domain == something.com OR domain == www.something.com)
{
    // The rules inside this scope will only apply to the domain:
    // something.com / www.something.com

    // This should match "something.com/test" and/or "www.something.com/test"
    RewriteRule /something /something/something.aspx
}


if (domain == test.com OR domain == www.test.com)
{
    // The rules inside this scope will only apply to the domain:
    // test.com / www.test.com

    // This should match "test.com/test" and/or "www.test.com/test"
    RewriteRule /test /test/test.aspx
}

The documentation is very confusing to me.

Any and all help is much appreciated.

+3  A: 

If ISAPI_Rewrite works the same as Apache’s mod_rewrite, try this:

RewriteCond %{HTTP_HOST} ^(www\.)?something\.example$
RewriteRule ^/something$ /something/something.aspx

RewriteCond %{HTTP_HOST} ^(www\.)?test\.example$
RewriteRule ^/test$ /test/test.aspx

Note: I used other domain names according to RFC 2606.


Edit: It seems that for ISAPI_Rewrite you have to replace the %{HTTP_HOST} by Host: to get the current host.

Gumbo
+2  A: 

This is the "old" syntax, used before version 3:

RewriteCond Host: ^(www\.)?something\.com$
RewriteRule ^/something$ /something/something.aspx

RewriteCond Host: ^(www\.)?something\.com$
RewriteRule ^/test$ /test/test.aspx

This would be the new syntax, for version 3 and up. This is closer to mod_rewrite:

RewriteCond %{HTTP:Host} ^(www\.)?something\.com$
RewriteRule ^/something$ /something/something.aspx

RewriteCond %{HTTP:Host} ^(www\.)?something\.com$
RewriteRule ^/test$ /test/test.aspx

The regex itself is the same in both versions.

Tomalak
I think the new syntax should be %{HTTP_HOST} (underscore instead of colon).
Sean Carpenter
This is what their own syntax converter tool gave me.
Tomalak
Both is valid: http://www.helicontech.com/isapi_rewrite/doc/RewriteCond.htm
Gumbo
Not so fast: %{HTTP:Host} accesses the raw header, whereas %{HTTP_HOST} accesses a server variable. Not every header has a corresponding server variable, but in this case they should both contain the same value. (I believe mod_rewrite cannot access the headers at all.)
Tomalak
A: 

Thanks for the effort Gumbo and Tomalak. Really appreciate it.

I've figured out another approach though: you put a file (httpd.ini) holding specific rewrite's to a specific virtual directory/domain in the root folder of that virtual directory/domain.

This eliminates polluting the global config file as well.

roosteronacid
How is that connected to your question? :-)
Tomalak
+1  A: 

Just a note that the per-directory httpd.ini method described above is not supported by the ISAPI 3 light version: http://www.helicontech.com/isapi_rewrite/doc/litever.htm

Wayne