I basically want to match the exact address
http://www.example.com/mysite
and redirect it to
http://www.example2.com/something/something
If possible I want to be able to do it with IIS because I have coded an internal rewriting module for example.com that rewrites user friendly URLS to aspx pages, and I don't want any interference with the other site.
NINJA EDIT:
I want to keep the address as http://www.example.com/mysite so I need to rewrite it not redirect it.
This should do the job:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect mysite" stopProcessing="true">
<match url="^mysite$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example2.com/something/something" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Related
We're trying to rewrite to a specific domain and subdirectory, when we rewrite to the domain it works fine but trying to get to the subdirectory either brings up the wrong page or doesn't work at all.
Here is what we have now that is working to rewrite the domain, but doesn't go to the proper subdirectory and page.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to site.firstdomain.com">
<match url="(.*)" ignoreCase="true" />
<action type="Rewrite" url="https://site.firstdomain.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
With the above set up entering https://site.seconddomain.com takes us to https://site.seconddomain.com/Account/Login?ReturnUrl=%2f
But we really want to go to
https://site.seconddomain.com/Account/Login?co=7xTixDp4F%2fzAp0WobaTTjw%3d%3d
But if I try
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to site.firstdomain.com">
<match url="(.*)" ignoreCase="true" />
<action type="Rewrite" url="https://site.firstdomain.com/Account/Login?co=7xTixDp4F%2fzAp0WobaTTjw%3d%3d" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
We still don't get taken to the https://site.seconddomain.com/Account/Login?co=7xTixDp4F%2FzAp0WobaTTjw%3D%3D address and the page displays the wrong images and then eventually Chrome says there is a memory error.
Is this something to do with the special characters in co=7xTixDp4F%2FzAp0WobaTTjw%3D%3D ?
Or I'm beginning to think this isn't a URL rewrite issue and is something with the page/system, any ideas?
Currently I have a sub-domain https://blog.example.com which I would like to redirect to https://example.com/blog. I'm using Craft CMS running on IIS 7 server.
I tried the code mentioned below but it didn't work:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect blog to new url" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern=".*" />
</conditions>
<action type="Redirect" url="https://example.com/blog/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Update: Adding directory structure
The problem seems to be with the condition you have specified. Your current pattern is .* which will result in a infinite loop. Change the pattern to check for the specific URL as below.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect blog to new url" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern=".*blog\.example\.com.*" />
</conditions>
<action type="Redirect" url="https://example.com/blog/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I tried this and it works for me. Go to http://blog.kaushal.co.in
If you need to troubleshoot URL Rewrite rules, then enable Failed Request tracing for your site. See this for more details: Using Failed Request Tracing to Trace Rewrite Rules
UPDATE
The rewrite rules need to be added to the 117072616095252 present at the site's root "/" and not in a web.config of one of the child folders.
I have a simple wildcard routing rule I want to apply for my Azure web app.
<rule name="MyRule">
<match url="*" />
<action type="Rewrite" url="/index.html" />
</rule>
Do I have any option here given I can't RDP into the machine and fiddle with IIS? This is not an ASP.Net website, it's a simple SPA application.
You need to create a web.config file in your wwwroot folder and put the relevant config entries there.
Here's an example of an web.config rule, to give you an idea of what it should look like.
The below example redirect the default *.azurewebsites.net domain to a custom domain (via http://zainrizvi.io/blog/block-default-azure-websites-domain/)
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect rquests to default azure websites domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^yoursite\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="http://www.yoursite.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
If simply want all URL's that resolve to this server & site to redirect to index.html you could use this rewrite section:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="SPA">
<match url=".*" />
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
This is very similar to what you have except some minor syntax fixes e.g. the pattern should be ".*" and the rewrite URL target simply "index.html".
Note this means that ALL URL's to your site will be rewritten, even for other resources like CSS and JS files, images etc. So you'd better be fetching your resources from other domains.
If you want to do actual rewrites (not redirects), dont forget enabling ARR with applicationHost.xdt file put to the site folder with the following content:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" />
<rewrite>
<allowedServerVariables>
<add name="HTTP_ACCEPT_ENCODING" xdt:Transform="Insert" />
<add name="HTTP_X_ORIGINAL_HOST" xdt:Transform="Insert" />
</allowedServerVariables>
</rewrite>
</system.webServer>
</configuration>
I need to redirect from
http://someserver/someapplication.page.aspx
to
http://someserver.domain.com/someapplication.page.aspx
Both the requests lead to the same server.
someserver/ works through our company's internal DNS
This is the same question as Redirecting to Full Domain
but I want an IIS solution for this, not code. My guess is it will have something to do with adding a httpRedirect add element in Configuration Editor using wildcards.
You can use URL Rewrite for that which is the recommended way to do it in IIS, simply add a web.config with a rule like:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to full domain" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^someserver$" />
</conditions>
<action type="Redirect" url="http://someserver.domain.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I have a website mywebsite.com and installed a cms into a sub folder: mywebsite.com/subfolder
I need to now move the cms to parent folder root and I would like url's to be rewritten automatically so when browsing mywebsite.com/subfolder/page1.php you get redirected to mywebsite.com/page1.php
so far the only suggestions I found were redirecting any request to the root folder. In my case I need to rewrite.
Thanks!
I guess the reason why your question is so old and has not been answered is because it is not clear what you are asking for. Using the IIS7 rewrite module is easy, and I will provide a couple of different examples for what I think you are asking (either or).
So if you would like to "rewrite" urls that are in a subfolder but have them appear as if they were in the root, the following would work -
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Root_URL_Rewrite" stopProcessing="true">
<match url="^(.*)" />
<action type="Rewrite" url="/subfolder/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
If however you would like url's in an old folder (say url's that have been indexed by google) to be redirected (as a permanent 301 redirect) you could use the following example -
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect_Root_URL" stopProcessing="true">
<match url="(.*)subfolder(.*)" ignoreCase="true" />
<action type="Redirect" url="{R:2}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Or, if like me you stumpled across this page and are wanting to do a rewrite to a subfolder, and then do a permanent 301 redirect from the old subfolder to the root, you might want something more similar to the following -
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect_Root_URL" stopProcessing="true">
<match url="(.*)subfolder(.*)" ignoreCase="true" />
<action type="Redirect" url="{R:2}" redirectType="Permanent" />
</rule>
<rule name="Root_URL_Rewrite" stopProcessing="true">
<match url="^(.*)" />
<conditions>
<add input="{URL}" pattern="^/subfolder/.*" negate="true" />
</conditions>
<action type="Rewrite" url="/subfolder/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>