IIS and Yii2 pretty URL - .htaccess

What is the .htaccess equivalent for IIS to enable pretty URLs in Yii2 on IIS. Indeed, I don't know what could I do with web.conf to allow those URLs.

try this on your web.config and save it on the root
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<rewrite>
<rules>
<rule name="Hide Yii Index" 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" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Related

IIS Rewrite rule multiple react apps

I have several spa applications under one address and one port.
Each application can be accessed, but not sub-addresses or sub-levels.
address1:port1/a/b/spa1 : ok
address1:port1/c/d/spa2 : ok
but
address1:port1/a/b/spa1/sub : error
address1:port1/c/d/spa2/sub/sub?aaa=aaa : error
I set web.config in IIS root directory.
Can't access sub-route
How do I set up the web.config in root directory or sp1, sp2 directory
My web.config set in address1:port1 directory.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="React Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

IIS 10 - JSON files are not serving even after configured MIME and Handlers

I have deployed a web application in IIS 10 (Windows 10) build from Node.
Files structure
I am unable to access the JSON files (for eg., http://localhost:3000/manifest.json) using the direct URL.
Receiving the following error,
I have set MIME Type as follows,
I have tried the Handler Mapping too,
My web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Static Assets" stopProcessing="true">
<match url="([\S]+[.](html|htm|svg|js|css|png|gif|jpg|jpeg|json))" />
<action type="Rewrite" url="/{R:1}" />
</rule>
<rule name="ReactRouter Routes" 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.html" />
</rule>
</rules>
</rewrite>
<handlers>
<add name="StaticFileModuleJson" path="*.json*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
</handlers>
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
I notice that your rewrite rule have rewritten .json to .js. It has nothing to do with the handler because static file hanlder is still handling the request.
Please swap the index of js and json.
<rule name="Static Assets" stopProcessing="true">
<match url="([\S]+[.](html|htm|svg|json|css|png|gif|jpg|jpeg|js))" />
<action type="Rewrite" url="/{R:1}" />
</rule>

Zend Framework 2 in IIS in subdirectory

My ZF2 project is in a subdirectory within my IIS 7.5 server, but the rewrite doesn't work.
The application only works through www.domain.com/directory/subdirectory/public/index.php/controller/action.
How can I configure rewrite in IIS
You need to configure the build rewrite engine in IIS. Put this file into web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^.*$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}"
matchType="IsFile" pattern=""
ignoreCase="false" />
<add input="{REQUEST_FILENAME}"
matchType="IsDirectory"
pattern=""
ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^.*$" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
More information:
Zend Framework 2 Installation
URL Rewrite

web.config rewrite index.php for subdirectory

On a server there are two webapps, a wordpress website, and a 'standalone' website in a subdirectory.
Both apps need a rewrite for index.php, and for wordpress this was done automatically, but now I also need a rewrite for the other app in the subdirectory.
To further clarify:
http://www.example.com/contact should redirect to http://www.example.com/index.php/contact
http://www.example.com/subfolder/contact should redirect to http://www.example.com/subfolder/index.php/contact
It seems like a rather simple thing to do, but I can't seem to figure it out...
This is the web.config I have right now, how can I fix this?
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear/>
<add value="index.php"/>
<add value="Default.htm"/>
<add value="Default.asp"/>
<add value="index.htm"/>
<add value="index.html"/>
<add value="iisstart.htm"/>
<add value="default.aspx"/>
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard">
<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"/>
</rule>
<rule name="standalone" 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" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

IIS URL Rewriting - Rule captures despite file existing

I've got a rule that rewrites URLs unless a physical file exists (so static files can be returned) - however for some reason the rules get rewritten anyway, to much frustration.
Here's my Web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Front Page">
<match url="/?" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="/Home/FrontPage" />
</rule>
<rule name="Map Everything" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="EntryPoint.php/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
Ah, it turns out the "Front Page" rule was the problem, and the rule "/?" was matching everything when I should have used "^$" instead.
After fixing that, the IsFile/IsDirectory rules were being respected.

Resources