I wanna convert this apache .htaccess lines to web.cofig:
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=302]
with these codes I ca开发者_StackOverflow社区n redirect all request with www. even if my website has too many domains.
I research and found my answer. for use variables in conditions we can use {C:1}. that 1 is for first match. and my ecxact answer for this converting is:
<rules>
<rule name="http Redirect" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.(.*)$" />
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="http://{C:1}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="https Redirect" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.(.*)$" />
<add input="{SERVER_PORT_SECURE}" pattern="^0$" negate="true" />
</conditions>
<action type="Redirect" url="https://{C:1}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
That is equal to:
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteCond %{HTTPS} ^off$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,QSA,R=302]
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteCond %{HTTPS} ^on$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [L,QSA,R=302]
Good Luck
精彩评论