#azure #mod-rewrite #iis #web-config
#azure #мод-переписать #iis #web-config
Вопрос:
Я меняю «URL как параметр» с помощью Apache .htaccess, используя флаг [B]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{THE_REQUEST} s/ (S )
RewriteRule (.*) index.php?i=%1 [B,L]
К сожалению, не могу понять, как сделать то же самое в IIS web.config
<configuration>
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear/>
<add value="index.php"/>
</files>
</defaultDocument>
<modules runAllManagedModulesForAllRequests="true"/>
<rewrite>
<rules>
<rule name="rule" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?i={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Допустим, web.config находится под http://localhost/dir/web.config …
Результаты: Открытие http://localhost/dir / и http://localhost/dir/example выполняет index.php правильно, но доступ к http://localhost/dir/i/http://example.org возвращает ошибку 500 The page cannot be displayed because an internal server error has occurred.
http://localhost/dir/i/http://example.org Ожидаемый: должен выполнить index.php со $_GET['i']
значением dir/i/http://example.org
Кажется, IIS не позволяет использовать в URL :/
… Любое обходное решение / исправление для этого?
Такие инструменты, как http://www.htaccesstowebconfig.com неправильно конвертирует .htaccess, ваша помощь / совет будут очень признательны.
Ответ №1:
Единственный способ, которым я нахожу способ отвечать на URL-адреса, содержащие :/
и возвращающие значение / запрос с несколькими косыми ://...
чертами (пример URL http://localhost/dir/i/http://example.org ) был с помощью UNENCODED_URL
; fallowing ответ:
<rule name="Index" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?i={UNENCODED_URL}" appendQueryString="true" />
</rule>
Обратите внимание, что оно вернет значение, начинающееся /
как /dir/i/http://example.org
.
Любой взлом для разрешения специальных символов, таких как
<system.web>
<httpRuntime requestValidationMode="2.0" requestPathInvalidCharacters="" relaxedUrlToFileSystemMapping="true" AllowRestrictedChars="1" UrlSegmentMaxLength="2048" />
<pages validateRequest="false" />
</system.web>
<security>
<requestFiltering allowDoubleEscaping="false" />
</security>
не дало никаких преимуществ для решения проблемы (в этом нет необходимости).
Обновление: он отлично работает на локальном компьютере с Windows 10, но по-прежнему возвращает ошибку 500 на серверах Azure. Понятия не имею, почему.
ModuleName IIS Web Core
Notification BEGIN_REQUEST
HttpStatus 500
HttpReason Internal Server Error
HttpSubStatus 19
ErrorCode The specified path is invalid.
(0x800700a1)
ConfigExceptionInfo \?D:homesitewwwrootihttp:web.config ( 0) :Cannot read configuration file