Rewrite condition htaccess to web.config - .htaccess

I would like to understand how the following htaccess file conditions translate for the web.config:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

You can convert htaccess conditions automatically by using the IIS URL Rewrite Module, you can find the explanation here.
This are your rules converted:
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?{R:1}" appendQueryString="true" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{THE_REQUEST}" pattern="^[A-Z]{3,}\s(.*)/index\.php" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{C:1}" />
</rule>
</rules>
</rewrite>

Related

i can not remove index.php from url in codeigniter in iis server

I can not remove the index.php from url in IIS. Here my .htaccess file;
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
also i tried the steps from codeigniter link but it didn't work for my server. it says only for apache servers. but im using iis server. even i enabled rewrite module but it didnt work again.
You should include this in your Web.config which is located in the root of your project:
<rule name="Remove index" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>

mod rewrite to IIS rewrite rule issue

Hi im getting these errors when im trying to to convert this file in IIS mod_rewrite
This directive was not converted because it is not supported by IIS:
RewriteBase /php-login/
And
The condition pattern is not supported: -l
Options -MultiViews
RewriteEngine On
RewriteBase /php-login/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Here it is in XML view with the errors please have a look at the errors
<rewrite>
<!--This directive was not converted because it is not supported by IIS: RewriteBase /php-login/.-->
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.+)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<!--The condition pattern is not supported: -l.-->
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
So the features in question are probably not supported by IIS and you
either have to do without them or figure out how to replace them with
whatever is supported. You may want to reformulate your question
accordingly. – SVD Mar 19 at 22:17

Convert htaccess file to web.config to run Php on IIS 7

I need to convert .htaccess to web.config in order to run php on iis 7. Any Ideas?
Options +FollowSymLinks +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /test
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php
The URL Rewriting module's import rules from .htaccess wizard generated the following rules:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="non-existent paths to index.php">
<match url="^test/(.+)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="test/index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The request /test/ will cause IIS to fire /test/index.php so (.*) is unnecessary and (.+) is more appropriate.

Modx Evolution Rewrite URL Web.Config IIS

I need help converting htaccess into web.config for IIS server.
This htaccess is used by Modx Evolution 1.x
#php_flag register_globals Off
#AddDefaultCharset utf-8
#php_value date.timezone Europe/Moscow
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]
# Rewrite domain.com -> www.domain.com -- used with SEO Strict URLs plugin
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
#RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# Exclude /assets and /manager directories and images from rewrite rules
RewriteRule ^(manager|assets)/*$ - [L]
RewriteRule \.(jpg|jpeg|png|gif|ico)$ - [L]
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I need to convert this configuration into web.config for IIS server.
Put this as web.config in the root folder of your webserver, change example.com to your domain name:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="Default.aspx" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Add WWW prefix" >
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}"
redirectType="Permanent" />
</rule>
<rule name="ModX IIS7 Rule 1" stopProcessing="true">
<match url=".*" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_USER_AGENT}" pattern="^.*internal\ dummy\ connection.*$" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="ModX IIS7 Rule 2" stopProcessing="true">
<match url="^(manager|assets)" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="ModX IIS7 Rule 3" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Convert web.config file to .htaccess

I'm looking for a way to convert my IIS rewrite rules to an .htaccess file. I couldn't find any tool to automatically do this and all I can get myself is 500 Internal Server Errors.
The web.config file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="RemoveTrailingSlash" stopProcessing="true">
<match url="^(.*?)/+$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:1}" />
</rule>
<rule name="HaltOnTinyMCE" stopProcessing="true">
<match url="^tinymce/.*$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="None" />
</rule>
<rule name="RewriteContent" enabled="true" stopProcessing="true">
<match url="^.*\.(gif|jpg|png|css|js|swf|txt|xml)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="domains/{HTTP_HOST}/{R:0}" appendQueryString="true" logRewrittenUrl="false" />
</rule>
<rule name="RewritePages" enabled="true">
<match url="^.*$" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="index.php" logRewrittenUrl="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
My best try at manually converting this is still giving me the 500 Internal Server Error. Any suggestions?
RewriteEngine on
RewriteCond /+$
RewriteRule ^(.*?)/+$ http://{HTTP_HOST}/$1 [R=301,L]
RewriteCond ^tinymce/.*$
RewriteRule ^(.*)$ $1 [L]
RewriteCond \.(gif|jpg|png|css|js|swf|txt|xml)$
RewriteRule ^.*\.(gif|jpg|png|css|js|swf|txt|xml)$ domains/{HTTP_HOST}/$1 [L]
RewriteRule ^.*$ index.php
Thanks in advance!
You were heading in the right direction, but there were a few errors, and unneeded things. This is what I came up with:
RewriteEngine on
RewriteBase /
#remove tailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ http://%{HTTP_HOST}/$1 [R=301,L]
# stop rules below from being applied if url starts with tinymce/
RewriteRule ^tinymce/.*$ - [L]
#rewrite images etc. to domains folder (unless url already starts with domain/)
RewriteCond $0 !^domains/
RewriteRule ^.*\.(gif|jpg|png|css|js|swf|txt|xml)$ domains/%{HTTP_HOST}/$0 [L]
#catch all other (I added 2 rewriteconds, to prevent rewriting existing files (including index.php))
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php

Resources