如何在.htaccess和web.config之间进行翻译?

时间:2013-03-01 00:33:46

标签: .htaccess iis url-rewriting web-config rewrite

我没有任何控制面板工具的访问权限,也不知道如何正确地执行此操作。我创建了以下重写规则以节省大量工作 - 但是在实现服务器的Microsoft之后,这并没有得到很好的解决。

RewriteRule ^scotsman-photo-products-([A-Za-z0-9-_]+)/?$ scotsman-photo-products.php?pg=$1 
RewriteRule ^make-scotsman-photo-([A-Za-z0-9-_]+)/?$ make-scotsman-photo.php?pg=$1 

似乎对配置文件所做的任何更改都会产生500错误 - 除非通过“官方”路由,否则服务器是否可能不允许任何更改?

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <add value="index.php" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

是当前的内容。

1 个答案:

答案 0 :(得分:7)

<rewrite>
    <rules>
    <rule name="Rule Name" stopProcessing="true">
    <match url="^scotsman-photo-products-([A-Za-z0-9-_]+)/?$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{SCRIPT_NAME}" pattern="^/(files|images|js|css|robots.txt|sitemap.xml|favicon.ico)($|/.*$)" negate="true" />
    </conditions>
    <action type="Rewrite" url="scotsman-photo-products.php?pg={R:0}" />
</rule>
<rule name="Other Rule Name" stopProcessing="true">
    <match url="^make-scotsman-photo-([A-Za-z0-9-_]+)/?$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{SCRIPT_NAME}" pattern="^/(files|images|js|css|robots.txt|sitemap.xml|favicon.ico)($|/.*$)" negate="true" />
    </conditions>
    <action type="Rewrite" url="make-scotsman-photo.php?pg={R:0}" />
</rule>
</rules>
</rewrite>

我认为这可行。条件是可选的。

如果该位置实际存在文件,则第一个条件规定不使用该规则。第二个是类似的,如果它实际上是一个目录,它会停止。如果URL是在模式中找到的类型,则第三个使规则不运行。

相关问题