使用URL重写

时间:2015-08-13 23:01:18

标签: url-rewriting iis-8

我以前的网络服务器在每个网站的.conf文件中运行带有重写的apache。我甚至不认为自己是一个中间重写用户,所以这可能不太理想。我试图重现这个:

# except for requests for URL-path /abc/abc_system<whatever> 
RewriteCond %{REQUEST_URI} !^(/abc/abc_system|/abc/themes|/abc/admin.php)
RewriteCond %{HTTP_HOST} ^([^.]+\.)*abctest\.example\.com [NC]
RewriteRule ^/abc/(.*)$ /abc/index.php/abc/$1 [L]
# one
RewriteRule ^/one/(.*)$ /one/index.php/one/$1 [L]
# two
RewriteRule ^/two/(.*)$ /two/index.php/two/$1 [L]
# three
RewriteRule ^/three/(.*)$ /three/index.php/three/$1 [L]
使用URL Rewrite在IIS 8中

<rewrite>
    <rules>
        <clear />
        <rule name="abc ee" stopProcessing="false">
            <match url="^abc/(.*)$" ignoreCase="true" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{URL}" pattern="^(/abc/abc_system|/abc/themes|/abc/admin.php)" ignoreCase="false" negate="true" />
                <add input="{HTTP_HOST}" pattern="^([^.]+\.)*abctest\.example\.com" />
            </conditions>
            <action type="Rewrite" url="/abc/index.php/abc/{R:1}" logRewrittenUrl="true" />
        </rule>
        <rule name="abc one" stopProcessing="false">
            <match url="^/one/(.*)$" ignoreCase="true" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            </conditions>
            <action type="Rewrite" url="/one/index.php/one/{R:1}" logRewrittenUrl="true" />
        </rule>
    </rules>
</rewrite>

第一个规则是工作,但第二个规则(&#34; abc one&#34;)不是,所以我甚至不打算添加&#34;两个&#34;和&#34;三&#34;爱好。

基本上网址看起来像这样:

example.com/abc - &gt; example.com/abc/index.php/abc(working)

example.com/one - &gt; example.com/one/index.php/one

example.com/two - &gt; example.com/two/index.php/two

example.com/three - &gt; example.com/three/index.php/three

第二条规则不起作用,我做错了什么? 一旦修复,重复它是最好的方法,还是有更有效的方法来缩小它们?

非常感谢!

1 个答案:

答案 0 :(得分:0)

你可以使用&#34; OR&#34;为了抓住这两个/三个案例并且会更快,我测试了以下规则,它运行良好:

            <rule name="RewriteOneTwoThree" stopProcessing="true">
                <match url="^(one|two|three)/(.*)$" ignoreCase="false" />
                <action type="Rewrite" url="/{R:1}/index.php/{R:1}/{R:2}" />
            </rule>