IIRF URL rewrite to force www prefix: example.com -> www.example.com

好久不见. 提交于 2019-12-10 23:57:53

问题


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


回答1:


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.




回答2:


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]


来源:https://stackoverflow.com/questions/1495165/iirf-url-rewrite-to-force-www-prefix-example-com-www-example-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!