IIS不编码utf-8网址? [英] IIS does not encode utf-8 urls?

查看:51
本文介绍了IIS不编码utf-8网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在IIS7服务器上运行Joomla 2.5.

问题是Joomla的搜索引擎友好网址无法正常工作.无论我输入什么URL,它都将进入index.php.

经过艰苦的一天,努力编写规则和IIS设置后,我得到了两种认识:

  1. 仅当url为unicode时,搜索引擎友好的url才会被破坏.

  2. 在我的WAMP服务器中,SEF URL可以在其上完美运行:

    $_SERVER['REQUEST_URI']"mydomain/%D9%85%D8%AD%D8%B5%D9%88%D9%84%D8%A7%D8%AA/%D9%82%D9%84%D8%A8%DB%8C-%D8%B9%D8%B1%D9%88%D9%82%DB%8C"

    但是在IIS中

    $_SERVER['REQUEST_URI']"mydomain/???????/????-?????"

URL似乎没有经过URL编码.

  • 我已启用unicode别名,搜索引擎友好的url,并在Joomla的全局配置中进行了重写.

  • 我已将web.config.txt复制/粘贴到我的web.config中.

这是我的web.config文件:

 <?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appSettings />
  <connectionStrings>
     ****
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
    <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=****" />
    <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=****" />
    <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=****" />
      </assemblies>
    </compilation>
    <customErrors mode="Off" />
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
  </system.web>
    <system.webServer>
        <directoryBrowse enabled="false" />
        <defaultDocument>
            <files>
                <clear />
                <add value="Default.htm" />
                <add value="default.html" />
                <add value="Default.asp" />
                <add value="default.aspx" />
                <add value="default.php" />
                <add value="default.pl" />
                <add value="default.cgi" />
                <add value="index.htm" />
                <add value="index.html" />
                <add value="index.asp" />
                <add value="index.aspx" />
                <add value="index.php" />
                <add value="index.pl" />
                <add value="index.cgi" />
                <add value="iisstart.htm" />
                <add value="_holding.html" />
            </files>
        </defaultDocument>
        <security>
            <requestFiltering>
                <hiddenSegments>
                    <add segment="backup" />
                    <add segment="oldsite" />
                    <add segment="logs" />
                    <add segment="tmp" />
                    <add segment="upload" />
                </hiddenSegments>
            </requestFiltering>
        </security>
        <httpErrors>
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" path="/" responseMode="ExecuteURL" />
        </httpErrors>
        <rewrite>
            <rules>
                <clear />
                <rule name="Common Exploit Blocking" stopProcessing="true">
                    <match url="^(.*)$" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{QUERY_STRING}" pattern="mosConfig_[a-zA-Z_]{1,21}(=|\%3D)" />
                        <add input="{QUERY_STRING}" pattern="base64_encode.*\(.*\)" />
                        <add input="{QUERY_STRING}" pattern="(\&lt;|%3C).*script.*(\>|%3E)" />
                        <add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" />
                        <add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" />
                    </conditions>
                    <action type="Redirect" url="index.php" appendQueryString="false" redirectType="SeeOther" />
                </rule>
                <rule name="Joomla Search Rule" stopProcessing="true">
                    <match url="(.*)" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{URL}" pattern="^/search.php" ignoreCase="true" />
                    </conditions>
                    <action type="Rewrite" url="/index.php?option=com_content&amp;view=article&amp;id=4" />
                </rule>
                <rule name="Joomla Main Rewrite Rule" stopProcessing="true">
                    <match url="(.*)" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{URL}" pattern="(/[^.]*|\.(php|html?|feed|pdf|raw))$" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/" />
                </rule>
            </rules>
        </rewrite>
        <caching>
            <profiles>
                <add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" />
            </profiles>
        </caching>  
    </system.webServer>
</configuration>
 

解决方案

这是IIS7的一个已知错误,并且有针对它的修补程序,但是我处于托管环境中,没有特权安装修补程序.这是指向Microsoft支持网站的链接,其中包含详细说明和问题解决方案: FIX: URL包含UTF-8字符的请求发送到IIS 7.5时,取决于REQUEST_URI服务器变量可能失败

但是,如果您无法安装此修补程序,则可以通过以下解决方法使Joomla的SEF网址与unicode一起使用:

文档说php的$_SERVER['REQUEST_URI']不适用于unicode url重写,但是我发现参数可以完美地工作.我们可以将url作为参数发送到php代码,并将其分配给$_SERVER['REQUEST_URI']

  1. 按如下所示更改web.config文件中的第二个重写规则:

     <rule name="Joomla! Rule 2">
        <match url="(.*)" ignoreCase="false" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{URL}" pattern="^/index.php" negate="true" />
            <add input="{URL}" pattern="/component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="index.php?requesturi={URL}" />
    </rule>
     

    唯一的变化是修改<action>标签的url属性

  2. 在您的index.php(位于Joomla网站的根目录中)中,将其添加到顶部(在<?php开头标记之后)

     $_SERVER['REQUEST_URI'] = $_GET['requesturi'];
     

完成.您的美化网址中包含unicode.

I'm running Joomla 2.5 on an IIS7 server.

The problem is Joomla's search engine friendly urls don't work. Whatever url I enter, it goes to index.php.

After a painful day of struggling with rewrite rules and IIS settings, I came to two realizations:

  1. Search engine friendly urls are only broken when the urls are unicode.

  2. In my WAMP server, on which the SEF urls work perfectly:

    $_SERVER['REQUEST_URI'] is "mydomain/%D9%85%D8%AD%D8%B5%D9%88%D9%84%D8%A7%D8%AA/%D9%82%D9%84%D8%A8%DB%8C-%D8%B9%D8%B1%D9%88%D9%82%DB%8C"

    But in IIS

    $_SERVER['REQUEST_URI'] is "mydomain/???????/????-?????"

It looks like urls are not URLEncoded.

  • I have enabled unicode aliases, search engine friendly urls, and rewrite in Joomla's global configuration.

  • I have copy/pasted the web.config.txt into my web.config.

Here is my web.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appSettings />
  <connectionStrings>
     ****
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
    <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=****" />
    <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=****" />
    <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=****" />
      </assemblies>
    </compilation>
    <customErrors mode="Off" />
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
  </system.web>
    <system.webServer>
        <directoryBrowse enabled="false" />
        <defaultDocument>
            <files>
                <clear />
                <add value="Default.htm" />
                <add value="default.html" />
                <add value="Default.asp" />
                <add value="default.aspx" />
                <add value="default.php" />
                <add value="default.pl" />
                <add value="default.cgi" />
                <add value="index.htm" />
                <add value="index.html" />
                <add value="index.asp" />
                <add value="index.aspx" />
                <add value="index.php" />
                <add value="index.pl" />
                <add value="index.cgi" />
                <add value="iisstart.htm" />
                <add value="_holding.html" />
            </files>
        </defaultDocument>
        <security>
            <requestFiltering>
                <hiddenSegments>
                    <add segment="backup" />
                    <add segment="oldsite" />
                    <add segment="logs" />
                    <add segment="tmp" />
                    <add segment="upload" />
                </hiddenSegments>
            </requestFiltering>
        </security>
        <httpErrors>
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" path="/" responseMode="ExecuteURL" />
        </httpErrors>
        <rewrite>
            <rules>
                <clear />
                <rule name="Common Exploit Blocking" stopProcessing="true">
                    <match url="^(.*)$" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{QUERY_STRING}" pattern="mosConfig_[a-zA-Z_]{1,21}(=|\%3D)" />
                        <add input="{QUERY_STRING}" pattern="base64_encode.*\(.*\)" />
                        <add input="{QUERY_STRING}" pattern="(\&lt;|%3C).*script.*(\>|%3E)" />
                        <add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" />
                        <add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" />
                    </conditions>
                    <action type="Redirect" url="index.php" appendQueryString="false" redirectType="SeeOther" />
                </rule>
                <rule name="Joomla Search Rule" stopProcessing="true">
                    <match url="(.*)" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{URL}" pattern="^/search.php" ignoreCase="true" />
                    </conditions>
                    <action type="Rewrite" url="/index.php?option=com_content&amp;view=article&amp;id=4" />
                </rule>
                <rule name="Joomla Main Rewrite Rule" stopProcessing="true">
                    <match url="(.*)" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{URL}" pattern="(/[^.]*|\.(php|html?|feed|pdf|raw))$" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/" />
                </rule>
            </rules>
        </rewrite>
        <caching>
            <profiles>
                <add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" />
            </profiles>
        </caching>  
    </system.webServer>
</configuration>

解决方案

This is a known bug of IIS7 and there is a hotfix for it, but I am in a hosted environment without privileges to install hotfixes. Here's a link to the Microsoft support website with detailed explanation and the resolution for the issue: FIX: A PHP application that depends on the REQUEST_URI server variable may fail when a request whose URL contains UTF-8 characters is sent to IIS 7.5

But if you can't install the hotfix, here's a workaround to get Joomla's SEF urls work with unicode:

The documentation says php's $_SERVER['REQUEST_URI'] doesn't work with unicode url rewriting, but I figured out that parameters work perfectly. We can send the url as a parameter to the php code and assign it to $_SERVER['REQUEST_URI']

  1. Change your second rewrite rule in web.config file as follows:

    <rule name="Joomla! Rule 2">
        <match url="(.*)" ignoreCase="false" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{URL}" pattern="^/index.php" negate="true" />
            <add input="{URL}" pattern="/component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="index.php?requesturi={URL}" />
    </rule>
    

    The only change is modifying the url attribute of the <action> tag

  2. In your index.php (located at the root directory of your Joomla site), add this at the top (just after the <?php opening tag)

    $_SERVER['REQUEST_URI'] = $_GET['requesturi'];
    

Done. You have unicode in your beautified urls.

这篇关于IIS不编码utf-8网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆