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?
Related
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>
I'm migrating my blog from LAMP/PHP to IIS. To preserve the URLs, I'm using the URL Rewrite Module. Out of 192 pages, this works on 191. Essentially I need to replace the "index.php" portion of the URL with a directory name and append an ".html" suffix.
My RegEx pattern:
^myblog/index\.php/(.+)
My rewrite URL:
myblog/contents/{R:1}.html
This works in most cases, rewriting
http://www.MYSITE/myblog/index.php/2013/04/29/goto_slides
to
http://www.MYSITE/myblog/contents/2013/04/29/goto_slides.html
However, it fails in one case:
http://www.MYSITE/myblog/index.php/2013/04/29/goto_notes_evolving_java
This returns 404, and the error page says the requested URL is:
http://MYSITE:80/myblog/contents/2013/04/29/goto_notes_evolving_java
(Note that the ".html" suffix was not added; adding that finds the page.)
The only difference I can see between URLs that work and the one that doesn't is the trailing "java".
How can I fix or work around this?
The web.config, per request:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<rewrite>
<rules>
<clear />
<rule name="Rewrite blog URL from old PHP location" stopProcessing="true">
<match url="^myblog/index\.php/(.+)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="myblog/contents/{R:1}.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Removing the condition will fix your issue.
Your rule will become:
<rule name="Rewrite blog URL from old PHP location" stopProcessing="true">
<match url="^myblog/index\.php/(.+)" />
<action type="Rewrite" url="myblog/contents/{R:1}.html" appendQueryString="true" />
</rule>
I'm trying to set the canonical URL for my site (macton.com) to add the www in the beginning. The site is hosted using IIS and I installed the URL Rewriter Extension.
Here is the code I put in the web.config file. However, it doesn't seem to do anything, because it remains macton.com.
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to www" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^macton\.com$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://www.macton.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
After this I have a bunch of <location> tags with redirects that work fine. I tried using a redirect from macton.com → www.macton.com but that just creates an infinite redirect loop (DUH!)
Any idea why this wouldn't be working? Everywhere I look says this is the correct code!
This link can help:
http://www.awseibert.net/how-to/redirecting-canonical-names-in-iis-7
Have you also added macton.com to the binding of your website?
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>