I keep trying to convert the web.config file from my old server to the new one, which is using Ubuntu server, but I can't get the things done right. Can you guys help me to convert the code bellow to .htaccess?

    <rewrite>
  <rules>
    <rule name="Rule IIS7">
      <match url="^([a-zA-Z0-9-_.]+)(___)([0-9]+)(.*?)$" ignoreCase="false" />
      <conditions>
        <add input="{SCRIPT_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        <add input="{SCRIPT_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="post.php?redir=1&amp;id={R:3}" appendQueryString="false" />
    </rule>
    <rule name="Rule IIS7 2">
      <match url="(.*?)(_\!__)([0-9]+)(.*?)$" ignoreCase="false" />
      <conditions>
        <add input="{SCRIPT_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        <add input="{SCRIPT_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="links/cota_clicks.php?redir=1&amp;url={R:3}" appendQueryString="false" />
    </rule>
    <rule name="Redirect to WWW" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^todoespacoonline.com$" />
      </conditions>
      <action type="Redirect" url="http://www.todoespacoonline.com/{R:0}" redirectType="Permanent" />
    </rule>
    <rule name="Redirect to COM" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^todoespacoonline.com.br$" />
      </conditions>
      <action type="Redirect" url="http://www.todoespacoonline.com/{R:0}" redirectType="Permanent" />
    </rule>
    <rule name="Redirect to .COM" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="todoespacoonline.com.br$" />
      </conditions>
      <action type="Redirect" url="http://www.todoespacoonline.com/{R:0}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

I really couldn't do that on my own.

Dani AI

Generated

Below is a compact, practical .htaccess conversion that implements the behaviors shown earlier in this thread (canonical host redirects, the triple-underscore post id rewrite and the _!__ click tracker). It also includes the usual safeguards (skip real files/dirs, use 301 only after testing). Notes and troubleshooting follow the snippet.

# place at site document root
RewriteEngine On
RewriteBase /

# canonical host -> force www.todoespacoonline.com (uses HTTPS; change to http if you do not use TLS)
RewriteCond %{HTTP_HOST} !^www\.todoespacoonline\.com$ [NC]
RewriteRule ^ https://www.todoespacoonline.com%{REQUEST_URI} [L,R=301]

# do not rewrite existing files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# example: something___123  -> internal post.php?redir=1&id=123
RewriteRule ^([A-Za-z0-9_.-]+)___([0-9]+)(.*)$ /post.php?redir=1&id=$2 [L]

# example: anything_!__123 -> internal links/cota_clicks.php?redir=1&url=123
RewriteRule ^(.*)_!__([0-9]+)(.*)$ /links/cota_clicks.php?redir=1&url=$2 [L]

Key points and troubleshooting

  • Put host/canonical redirects first to avoid rewriting then redirecting (causes extra hops). ’s approach worked functionally but can produce double-redirects if ordering/flags differ.
  • The two RewriteCond %{REQUEST_FILENAME} checks replace IIS IsFile/IsDirectory conditions; they prevent breaking real files.
  • appendQueryString="false" in IIS maps to leaving off QSA in the flags; add [QSA] if you must preserve the original query string.
  • Test redirects as temporary (use R=302) while verifying, then flip to R=301. Clear browser cache when testing permanent redirects.
  • If rules are ignored: ensure mod_rewrite is enabled (sudo a2enmod rewrite) and the virtualhost allows .htaccess via AllowOverride All; reload Apache. For debugging enable LogLevel alert rewrite:trace3 and watch the error log.

If you want the site to preserve the original scheme (HTTP vs HTTPS) or to force http instead of https, swap the canonical rule accordingly. For other web.config rules in this thread (the .sn rewriting mentioned by and the favicon handling in ’s example) the same patterns (host redirect first, skip files/dirs, then rewrites) apply.

That wasn't really the same thing, but worked really well for me...

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$  [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$  [R=301,L]

RewriteCond %{REQUEST_URI} ([a-zA-Z0-9-_.]+)(___)([0-9]+) [NC]
RewriteRule ^([a-zA-Z0-9-_.]+)(___)([0-9]+)(.*?)$ post.php?redir=1&id=$3

Hello, plz convert to htaccess ?

 <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>
    <rewrite>
        <rules>
            <rule name="block favicon" stopProcessing="true">
                <match url="favicon\.ico" ></match>
                <action type="CustomResponse" statusCode="404" subStatusCode="1" 
                    statusReason="The requested file favicon.ico was not found" 
                    statusDescription="The requested file favicon.ico was not found" ></action>
            </rule>
            <rule name="Imported Rule 1" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" ></match>
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^mvc3$" ></add>
                </conditions>

                <action type="Redirect" redirectType="Permanent" url="http://localhost/LandlordApp/{R:1}" ></action>
            </rule>
            <rule name="Imported Rule 2" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" ></match>
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" ></add>
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" ></add>
                    <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" ></add>
                </conditions>
                <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" ></action>
            </rule>
        </rules>
    </rewrite>
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.