Я добавил ssl к iis на прошлой неделе и настроил правила перенаправления 301 в web.config моего сайта.
сегодня я заметил, что версия https://www не перенаправляется на версию https://без www моего веб-сайта, а такие ресурсы, как изображения и файлы css, доступны в обеих версиях моего веб-сайта.
верны ли эти правила, которые я добавил в свой web.config?
Из-за IIS и WordPress мне пришлось добавить перенаправление ресурсов и URL-адрес Unicode в web.config.
перенаправление с http на https работает
перенаправление с http//www на http://без www работает
но перенаправление с https//www на https://без www не работает!
мой файл web.config:
<rewrite>
<rules>
<rule name = "HTTPS" patternSyntax = "ECMAScript" stopProcessing = "true">
<match url = "(.*)" />
<conditions logicalGrouping = "MatchAll">
<add input = "{HTTPS}" pattern = "^OFF$" />
</conditions>
<action type = "Redirect" url = "https://{HTTP_HOST}{REQUEST_URI}"
redirectType = "Permanent" />
</rule>
<rule name = "Redirect Image to HTTP" stopProcessing = "true">
<match url = ".*\.(gif|jpg|jpeg|png|css|js|pdf|ttf|woff2|woff|mp4)$"
ignoreCase = "true" />
<action type = "Rewrite" url = "{R:0}" />
</rule>
<rule name = "WordPress Rule" stopProcessing = "true">
<match url = ".*" />
<conditions>
<add input = "{REQUEST_FILENAME}" matchType = "IsFile" negate = "true" />
<add input = "{REQUEST_FILENAME}" matchType = "IsDirectory" negate = "true" />
</conditions>
<action type = "Rewrite" url = "index.php" />
<serverVariables>
<set name = "REQUEST_URI" value = "{UNENCODED_URL}" replace = "true" />
</serverVariables>
</rule>
</rules>
Согласно вашему описанию, ваши правила кажутся без проблем, тогда кажется, что вы хотите понять, что измените любой запрос https, например https://www.example.com, на https://example.com, верно? Я сделал образец здесь. Вот правило, надеюсь, оно вам поможет.
<rule name = "rule1" stopProcessing = "true">
<match url = "(.*)" />
<conditions logicalGrouping = "MatchAll" trackAllCaptures = "false">
<add input = "{HTTPS}" pattern = "^on$" />
<add input = "{HTTP_HOST}" pattern = "www[.](.+)" />
</conditions>
<action type = "Redirect" url = "https://{C:1}/{R:0}" />
</rule>