Tomate
Tomate

Reputation: 308

How to translate between .htaccess and web.config?

I don't have any access to control panel tools, don't have a clue how to do this correctly. I created the following rewrite rules to save me a ton of work - but that's not worked out too well upon realising the server's 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 

seems any changes made to the config file create a 500 error - is it possible the server will not allow any changes unless through "official" routes?

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

Is the current content.

Upvotes: 0

Views: 1563

Answers (1)

Leeish
Leeish

Reputation: 5213

<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>

I think that might work. Conditions are optional.

The first condition states not to use the rule if there is in fact a file at that location. The second is similar in that it stops if that is in fact a directory. The third makes the rule not run if the URL is a type found in the pattern.

Upvotes: 7

Related Questions