I have two virtual machines. The first one (VM1) is running a web application with an URL like this:
VM1/servicedesk/customer/user/login
The second (VM2) should now redirect to this address without changing the URL and also doesn't allow to redirect to the root / since that is a different web-application. This works relatively easily with this rewrite rule:
<rule name="rewriteAll" stopProcessing="true">
<match url=".*" />
<action type="Rewrite" url="http://VM1/servicedesk/customer/user/login" />
</rule>
It just basically rewrites everything from VM2 to the specific VM1 URL.
The problem I'm facing is that this web-application has many Ajax calls to other addresses on the same VM1.
For example VM1/rest/... or VM1/s/.... I really tried to find each exceptional call and create a rule before this default Rewrite. But since some of them are nested and could be changed this isn't a good approach. So what i need is basically a rewrite without changing the URL what doesn't break the application that does a lot of nested calls.
I found out that i can use the following rule (redirectRest) before the existing rewriteAll rule to redirect subcalls (VM1/rest/..).
<rule name="redirectRest" stopProcessing="true">
<match url="/.*" />
<action type="Redirect" url="http://VM1/{R:0}" />
</rule>
<rule name="rewriteAll" stopProcessing="true">
<match url=".*" />
<action type="Rewrite" url="http://VM1/servicedesk/customer/user/login" />
</rule>
So basically when I call VM1 the second rule applies and I get rewritten to the web-app. The application hosted there will call e.g. VM1/rest what triggers the first rule and redirect the Ajax calls to the root. But I've found out that Ajax calls are not following a redirect like 301.
Related
We have a requirement for redirecting couple of webpages to different URLs of our website. For instance:
https://old-domain/-->https://new-domain/;
https://old-domain/promotion/campaign-->https://new-domain/;
https://old-domain/about-us-->https://new-domain/about-us/company;
https://old-domain/about-us/awards-and-recognitions-->https://new-domain/about-us/company;
https://old-domain/careers-->https://new-domain/careers/;
https://old-domain/careers/apply-for-a-job-->https://new-domain/careers/;
https://old-domain/claim-status-->https://new-domain/;
https://old-domain/contact-us-->https://new-domain/contact-us;
We need generic rewrite rules for the above, where
we either redirect to the desired destination URLs (manually hard-coding them in the rewrite rules)
or
add a single redirect rule for the first URL and regex expression to skip the rest (since the rest can be managed internally within the CMS but not the first)
I would do it via IIS Rewrite Rules in the web.config (unless the client requires to be able to edit those in the UI)
I would add a rule for each Url (or maybe combine a few where possible)
They could look like this:
<rewrite>
<rules>
<rule name="Redirect old domain" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="[www.]oldDomain.com$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.newDomain.com/{R:0}" />
</rule>
....
</rules>
</rewrite>
Edit: Updated the rule above so that it will cater for any page on the old domain and will redirect to the same page of the new domain.
Examples:
www.olddomain.com will redirect to www.newdomain.com
www.olddomain.com/about-us will redirect to www.newdomain.com/about-us
Now, you can create the /about-us page in Sitefinity and make it a redirect page and redirect to wherever you want.
I want to create a rule to redirect query to a page (which doesn't exist) to another
Example:
http://www.example.com/en/page.asp?id=2&...
to
http://www.example.com/en-US/newpage.asp?id=2&...
I use this rule:
<rule name="Redirect" stopProcessing="true">
<match url="page\.asp\?(.+)$" />
<action type="Rewrite" url="newpage.asp?{R:1}" />
</rule>
But this doesn't work... I got a 404 error...
What is my mistake?
Thanks
URL Rewrite's Rewrite action is only for rewriting the page URL that
gets displayed on the browser but it expects the original page to
exist on the server. For your case, you need a Redirect action.
The regex needs to be changed to reflect "en-US" in the final URL.
Try this code instead:
<rule name="Redirect" stopProcessing="true">
<match url="en/page\.asp\?(.+)$" />
<action type="Redirect" url="en-US/newpage.asp?{R:1}" redirectType="Permanent"/>
</rule>
The permanent redirect helps makes your website SEO (Search Engine Optimized) preventing search engine bots to index the old URL (and hence not splitting page ranks between the 2 URLs).
I am having a problem with an IIS7 Integrated Pipeline URL Rewrite.
For my particular scenario I need to rewrite/redirect part of the initial request as follows.
User enters http://savecontoso.com/files/123456789/somefile.html in the browser address bar.
User is redirected to http://savecontso.com/default.aspx?url= (results of url="default.aspx?url={R:1}")
This currently works as expected only if I create the initial request as such, http://savecontoso.com/default.aspx/files/123456789/somefile.html.
I must note that there is no actual directory of /files/ nor /123456789/ nor any file named somefile.html on the server. I simply need that entire path and filename appended to a query string.
This is my first day working with redirect/rewrite functions using IIS instead of page code behind and I have looked all around learn.iis.net, Google etc to no avail. I understand that rewriting takes place before page requests but for some reason my particular code requires a page request before firing the redirect.
I suspect it is because I am not triggering conditions at the initial request?
<rewrite>
<rules>
<rule name="1" stopProcessing="true">
<match url="(.*)(/files/\d+/.*html$)" />
<action type="Redirect" redirectType="Permanent" url="default.aspx?url={R:1}" />
</rule>
</rules>
</rewrite>
Most likely it does not work because of your match pattern:
the {R:1} will only match (.*) in your pattern, and will never match files/123...
URL in match pattern always starts with no leading slash: should be files/\d+... and not /files/\d+...
Try this one instead (works fine for me):
<rule name="1" stopProcessing="true">
<match url="^files/\d+/.*\.html$" />
<action type="Redirect" url="default.aspx?url={R:0}" redirectType="Permanent" />
</rule>
I'm trying to use the URL Rewrite module for IIS 7.5 to redirect all HTTP requests to HTTPS for my ASP.NET website. The site works fine at the moment but forces the user to type the https:// in the address bar.
I followed the instructions in this article. Everything seems to be fine: I've tried putting the rule in the web.config and it shows up in the UI as it should; I've also done the reverse and can see the changes in the web.config when I use the UI to add the rule. I have RequireSSL unchecked for the site. Unfortunately I still just get a 404 when I try to hit the site via http://.
I've tried a few different action urls including {HTTP_HOST}/{R:1} and the one shown below.. nothing works.
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"
redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
I'm fairly new to this and pretty frustrated at this point. Seems like this should be a lot easier. Any advice would be appreciated, thanks..
Reposting from ServerFault as it's been sitting unanswered for a while.
HTTP Error 404. The requested resource is not found
Do you actually have binding for HTTP 80 port? Sounds like you do not have it (only HTTPS).
The reason I'm asking is the quoted text is the exact message that I would see if I request unknown to IIS domain (when there is no catch-all defined) or domain is not bound to the requested port.
I want to ensure that anybody who goes to http://example.com/* gets automatically redirected to http://www.example.com/*. Currently, IIS allows either URL form to work, meaning that any page can be accessed at multiple URLs, which has a number of disadvantages (SEO, etc).
Is there any way to do this built into IIS (especially IIS 6) without setting up a third-party rewriting engine like this? It seems like a bazooka to kill a mosquito.
The easy way would be to simply remove the DNS entries for 'www.mysite.com', so the only DNS entries that exist are for 'mysite.com'.
Alternatively, here's a couple of techiques for redirecting to a canonical URI:
http://www.kalyani.com/2010/01/redirecting-to-canonical-url-in-iis7/
https://web.archive.org/web/20211020203216/https://www.4guysfromrolla.com/articles/072810-1.aspx
http://www.stevenhargrove.com/redirect-web-pages/
Basically you want to hand back a 301 Moved Permanently status for the non-canonical URIs, along with the canonical URI so the user agent may load it instead.
I have another solution for you:
<rule name="Canonical domain name" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>