1

私は自分の ISS サーバーで get simple cms を使用しています (実際には ISS を使用する必要があります) web.config

web.config ソース:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="GetSimple Fancy URLs" 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="?id={R:1}" />
            </rule>
     </rules>
    </rewrite>
</system.webServer>
</configuration>

/しかし、次のようなメインフォルダーとサブフォルダーの両方にある私のCMS /en

http://domainname.com/ (メインの cms) http://domainname.com/en/ (サブフォルダーの別の cms)

上記のweb.config場合、メインの cms は正常に機能しますが、サブフォルダーの cms は機能しません (以前のように 404 が返されます)

そのサブフォルダー ルールを に実装するにはどうすればよいweb.config fileですか? したがって、2cmは正常に機能しています。

同じ web.config ファイルをサブフォルダー ( /en) の下に配置しようとしましたが、うまくいきませんでした。

どうもありがとう、

4

1 に答える 1

0

まず、正規表現は、Web サイトの実質的にルートにある URL のみに一致します (例:domain.com/pageまたはdomain.com/anotherpage. のようなサブディレクトリには一致しませんdomain.com/subdir/page。しかし、それはあなたが望んでいることかもしれません。

/en同様に機能させるには、ルールを次のように変更します。

<rule name="GetSimple Fancy URLs" stopProcessing="true">
    <match url="^(en/)?([^/]+)/?$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="{R:1}?id={R:2}" />
</rule>

任意の 2 文字の言語コードで機能する、より一般的なソリューションが必要な場合は、これを使用します。

<rule name="GetSimple Fancy URLs" stopProcessing="true">
    <match url="^([a-z]{2}/)?([^/]+)/?$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="{R:1}?id={R:2}" />
</rule>

これはweb.config、ルート ディレクトリ内にある必要があります。

于 2012-11-16T12:14:43.153 に答える