Simply I have this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="index/page/method to index.php?page=page&method=method">
<match url="^index/([^/]+)/([^/]+)$" />
<action type="Rewrite" url="index.php?page={R:1}&method={R:2}" />
</rule>
<rule name="index/page to index.php?page=page">
<match url="^index/([^/]+)$" />
<action type="Rewrite" url="index.php?page={R:1}" />
</rule>
<rule name="index to index.php">
<match url="^index" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
When I call localhost I get the following:
HTTP-Fehler 500.19 - Internal Server Error
My problem is the first rule doesn't work :(
The rules work fine as I delete the first rule...
Can someone help me?
Edit by myself:
IIS doesn't like the &...so I changed it to & and it works fine^^
It is clear that you shoud use &, as Microsoft says so in its article,
http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
Related
I have what to me seems like a simple task with IIS URL Rewrite.
I need to redirect based on sub-domains to a main domain with a query string. For example
demo.domain.com needs to be redirected to www.domain.com/?key=demo
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="demo.domain.com" />
</conditions>
<action type="Redirect" url="www.domain.com/?key=demo" appendQueryString="false" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
What's happen when you digit demo.domain.com ?
Try to change your code like this :
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="^demo\.example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/?key=demo" appendQueryString="false" redirectType="Found" />
</rule>
</rules>
Look at the changes in line "add input=" and "action type="
I'm looking for the best way to redirect multiple URL's to one new URL.
I have the following URLS:
https://domain.app.company.com/application
https://application.app.company.com
And I want those to redirect to: https://application.domain.app.company.com
What would be the best way to go about this (in IIS)?
I have tried using URL Rewriting, but I can only make that work for the first URL (https://domain.app.company.com/application):
<rule name="Application 1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*application" />
<action type="Redirect" url="https://application.domain.app.company.com" appendQueryString="false" />
</rule>
For the second URL (https://application.app.company.com), I can make it work when setting up a new (empty) website in IIS (that listens to said URL) and add a httpRedirect in it.
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="https://application.domain.app.company.com" exactDestination="true" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
Is this the recommended way to go about this? Or would there be another way?
Thank you
Schoof
If you want to bind two url for the same IIS web site, I suggest you could try to below url rewrite. We could create two url rewrite rule to achieve your requirement.
<rule name="Application 1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*application" />
<action type="Redirect" url="https://application.domain.app.company.com" appendQueryString="false" />
</rule>
<rule name="test" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="application.app.company.com" />
</conditions>
<action type="Redirect" url="https://application.domain.app.company.com" />
</rule>
I have a redirect rule that I am trying to create using web.config. I am trying to redirect
from the below page:
https://example.org/content/content.php?PrintMe=0&PgName=gothedistance
to this page:
https://example.org/gothedistance
My url redirect rule looks like the below:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="content.php$" />
<conditions>
<add input="{QUERY_STRING}" pattern="PrintMe=0&PgName=gothedistance" />
</conditions>
<action type="Redirect" url="gothedistance" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
My URL Rewrite rule only works for port 80 in IIS .
The rewrite works for : http://localhost:80 --> http://localhost:8100
The rewrite works for : http://localhost:80/redirect --> http://localhost:8100
The rewrite doesnt work for : http://localhost:8080 --> http://localhost:8100
The rewrite doesnt work for : http://localhost:8080/redirect --> http://localhost:8100
My web.config is following:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension, LongDate" />
<rewrite>
<rules>
<rule name="Redirect to port 8100" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT}" pattern="^8100$" negate="true" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}:8100/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The web.config is only working on default http port 80/443 but not for an specific port.
Which changes has to be made in the web.config for working with all ports?
The main problem is the variable {HTTP_HOST} which already contains the PORT information.
To solve this issue you need to adjust two things:
Extend the matching pattern within
Set the correct address for the redirect
I adjusted your web.config to see how it should work with your example:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension, LongDate" />
<rewrite>
<rules>
<rule name="Redirect to port 8100" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" >
<add input="{HTTP_HOST}" pattern="([^/:]*?):[^/]*?" />
</conditions>
<action type="Redirect" url="http://{C:1}:8100/{R:0}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I would like this URL
http://alpha.Mysite.io/Car/Details/{4f2a95ed-3582-4486-8ef6-8a8e6731161f}
to redirect to
http://alpha.Mysite.io/Car/index.htm?Action=Details&guid={4f2a95ed-3582-4486-8ef6-8a8e6731161f}
The GUID parameter ({4f2a95ed-3582-4486-8ef6-8a8e6731161f}) is differenet each time so needs to be passed to the redirected URL.
I have the basic redirect working using a ReWriteMap, however as soon as I add the nameless GUID paramter I get a 404 instead
Here's my section from webconfig
<rewrite>
<rules>
<rule name="Rewrite rule1 for carAPI">
<match url=".*" />
<conditions>
<add input="{carAPI:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="true" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="carAPI">
<add key="/car/details/" value="/car/index.asp?Action=Details" />
</rewriteMap>
</rewriteMaps>
</rewrite>
In your case, you do not need rewrite map. You can achieve everything with single rule:
<rule name="Rewrite rule1 for carAPI" enabled="true" stopProcessing="true">
<match url="^Car/Details/([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})" />
<action type="Rewrite" url="/Car/index.htm?Action=Details&guid={R:1}" appendQueryString="false" />
</rule>
This rule will match urls like Car/Details/{any valid .net guid} and rewrite them into Car/index.htm?Action=Details&guid={guid}