<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirection Https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
                </rule>
                <rule name="REWRITE_TO_HTML" stopProcessing="true">
                    <match url="^(.+).html$" />
                    <conditions logicalGrouping="MatchAll" />
                    <action type="Redirect" url="{R:1}.sn" />
                </rule>
                <rule name="REWRITE_TO_PHP" stopProcessing="true">
                    <match url="^(.+).php$" />
                    <conditions logicalGrouping="MatchAll" />
                    <action type="Redirect" url="{R:1}.sn" />
                </rule>
                <rule name="test1">
                    <match url="^(.*)\.sn" />
                    <action type="Rewrite" url="{R:1}.php" />
                </rule>
                <rule name="tttt" stopProcessing="true">
                    <match url="^(.+).php(.+)" />
                    <action type="Redirect" url="{R:1}.sn{R:2}" />
                </rule>
                <rule name="tttt1" stopProcessing="true">
                    <match url="^(.+).html(.+)" />
                    <action type="Redirect" url="{R:1}.sn{R:2}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Dani AI

Generated

If you want Apache to behave like the web.config shown (force HTTPS, redirect .html/.php to .sn, but serve .sn from the underlying .php), drop an .htaccess like this in your web root. Order matters to avoid loops.

# Turn off content negotiation that can conflict with rewrites
Options -MultiViews

RewriteEngine On
RewriteBase /

# 1) Force HTTPS (works behind proxies/CDNs too)
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# 2) Canonicalize extensions to .sn (permanent redirects)
RewriteRule ^(.+)\.html(.*)$ $1.sn$2 [R=301,L,NC]
RewriteRule ^(.+)\.php(.*)$  $1.sn$2 [R=301,L,NC]

# 3) Internally rewrite .sn to the real PHP script
RewriteRule ^(.+)\.sn$ $1.php [L]

Notes and tips:

  • Use 302 while testing, then switch to 301 to avoid caching bad redirects.
  • If you do not run behind a proxy/CDN, you can drop the X-Forwarded-Proto condition.
  • This preserves query strings automatically; PATH_INFO (e.g., file.php/extra) is captured by (.*) and forwarded to .sn as in your IIS rules.
  • Ensure mod_rewrite is enabled and .htaccess is allowed: a2enmod rewrite, then in your vhost use AllowOverride FileInfo Options.
  • Apache rewrite docs are an invaluable reference: see mod_rewrite overview and RewriteRule flags.

Recommended Answers

All 4 Replies

<rewrite> <rules> <rule name="test" patternSyntax="Wildcard"> <match url="" negate="false" /> <conditions> <add input="{URL}" pattern="/abc" /> </conditions> <action type="Rewrite" url="" /> </rule> <rule name="test2" patternSyntax="Wildcard"> <match url="" negate="false" /> <conditions> <add input="{HTTP_REFERER}" pattern="abc" /> </conditions> <action type="Rewrite" url="}" /> </rule> </rules> </rewrite>

Well, there is no such tool to convert web.config into .htaccess file.

<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Redirect to WWW" stopProcessing="true"> <match url="^$" /> <action type="Redirect" url="" redirectType="Permanent" /> </rule> <rule name="Index"> <match url="^(.*)$" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" /> </rule> </rules> </rewrite> <httpErrors errorMode="Detailed" /> </system.webServer> </configuration>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.