IIRF URL rewrite to force www prefix: example.com

2019-07-18 00:32发布

I'm trying to do something pretty simple in iirf.

I want all requests that are missing the www. prefix to have it added.

This is my IsapiRewrite4.ini:

RewriteCond %{HTTP_HOST} ^example\.com$ [I]
RewriteRule ^(.*)$ www.example.com/$1 [R=301,L]

This is my SampleUrls.txt:

example.com
example.com/grants
www.example.com
www.example.com/grants

I place the files in the same directory as TestDriver.exe, and run testdriver -d . All the tests are ignored:

NO ACTION 'example.com' ==> --

NO ACTION 'example.com/grants' ==> --

NO ACTION 'www. example.com' ==> --

NO ACTION 'www. example.com/grants' ==> --

Thanks,

Ashley

2条回答
走好不送
2楼-- · 2019-07-18 00:40

The TestDriver is a standalone tool to test rewrite rules for IIRF. Unfortunately, the tool is limited, in that it cannot effectively evaluate conditions that test Server variables. There are no server variables in a standalone console-based application.

Check the doc. Here's what it says:

Please note: the TestDriver.exe program is a useful testing tool, but it does not and cannot replace actual testing in the context of a web server. The testdriver does not run within the context of an HTTP server, and so does not work with HTTP Server variables. In particular, if you use RewriteCond in the ini files that you test with TestDriver.exe, and those RewriteCond statements reference Server variables (eg %{HTTP_URL} or %{HTTP_REFERER}) , those RewriteCond statements will not behave in the TestDriver the same way they will behave in an ISAPI. Tests of such conditions will not be useful in verifying actual operational performance.

查看更多
放荡不羁爱自由
3楼-- · 2019-07-18 00:40

You need to specify an absolute URL for the substitution. Otherwise your www.example.com is treated as path segment.

RewriteCond %{HTTP_HOST} ^example\.com$ [I]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
查看更多
登录 后发表回答