How to Redirect a Domain without Changing the URL in web.config file? - redirect

I setup a redirect from one domain (https://test.mydomain.com) to another URL (http://testing.com/test/Login.aspx) and I want to keep the domain name in the address bar. Basically, Redirect website visitors to another site, but do not show them the destination address, so they do not know about the redirection.
This is for a windows server 2008 r2, running iis 7. I would like to amend the web.config file.
I expect the redirect to keep the original domain (https://test.mydomain.com).

According to your description, I suggest that you use URL Rewrite.
First add the condition to check whether URL is a https request, then add another condition to check the domain of URL. Add the rule below to your web.config file.
<rule name="test url rewrite">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="on" />
<add input="{HTTP_HOST}" pattern="test.mydomain.com" />
</conditions>
<action type="Rewrite" url="http://testing.com/test/Login.aspx" />
</rule>

Related

Restrict requests by HTTP referer - IIS

I have an IIS website at mydomain.com/mywebsite which has a URL rewrite request that for any requests to a 'maps' path (mydomain.com/mywebsite/maps) through the website, it will redirect requests to an external site to retrieve mapping image tiles that display on the page.
If someone tries to go to mydomain.com/mywebsite/maps on their browser, I do not want it to be accessible as I want to restrict these requests only to the website.
How can I set up a restrict rule in IIS to configure this?
You can try to create a request blocking rule for this, here a example for you as reference:
<rule name="RequestBlockingRule1" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{URL}" pattern="^maps$" />
</conditions>
<action type="AbortRequest" />
</rule>
I have managed to restrict access to the URL path by adding an HTTP_REFERER condition in my URL inbound rewrite rule so it only accepts requests from my website domain which seems to work.
<conditions>
<add input="{HTTP_REFERER}" pattern="*mywebsite.com*" />
</conditions>

IIS 10 URL redirect from one domain to another

I would like to redirect a specific site from one domain to another and i have tried the following URL redirect. Not sure where i am going wrong.
I have an app at http://www.a.b.com/myapp/index.aspx
I would like to redirect it to
http://www.a.c.com/myapp/index.aspx
<rule name="testredirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^myapp/index.aspx$" />
<action type="Redirect" url="http://www.a.c.com/{R:0}" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.a.b.com$" />
</conditions>
</rule>
The rule work perfectly on my side. Please try to clean browser cache and post your detailed error message. Please ensure you are running the rule in the right place and has been enabled.
Besides, please check whether the incoming request is reaching the correct application pool.

IIS URL Redirect with input parameters

Having trouble implementing my first IIS redirect.
I have a URL:
domain.com/Q7WebServer/Q7WebSrv.exe/datasnap/rest
It can accept a range of input parameters separated by / characters:
domain.com/Q7WebServer/Q7WebSrv.exe/datasnap/rest/GetDateTime
domain.com/Q7WebServer/Q7WebSrv.exe/datasnap/rest/GetUsageData
etc, etc.
I'd like to redirect to a new module (a DLL in fact):
domain.com/Q7WebServer/Q7WebSrvISAPI.dll/datasnap/rest
I started by adding my redirect to the file itself (Q7WebSrv.exe) and it works fine by itself. It's only when I add variables that it starts behaving in ways I don't understand. For example if I have the redirect set to Q7WebSrvISAPI.dll$V$Q (using the EXACT flag) and request
domain.com/Q7WebServer/Q7WebSrv.exe
I get back
domain.com/Q7WebServer/Q7WebSrvISAPI.dll/Q7WebServer/Q7WebSrv.exe
No matter which $ variables I use, it's still trying to append part of the original URL to the redirect. I don't even want to get into what happens when appending the / input parameters.
Do I need to get into URL rewriting? That's a whole can of worms I'm not wanting to open just yet.
you could try this rule:
<rule name="test" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.domian.com" />
<add input="{REQUEST_URI}" pattern="/Q7WebServer/Q7WebSrv.exe/datasnap/rest/(.*)" />
</conditions>
<action type="Redirect" url="http://ww.domain.com/Q7WebServer/Q7WebSrvISAPI.dll/datasnap/rest/{C:1}" />
</rule>

301 Redirect one domain to another using web.config

I have multiple domains pointing to one hosting location.
I wish to establish one of the domains as my main domain and therefore I wish to perform a 301 redirect to this main domain whenever a user accesses my site from a secondary domain.
For example:
www.example.com
This is my main domain. I want all other domains associated with my site to redirect to here.
If a user comes in on:
www.test.com or
www.test.com/anypage
etc.
Then I want the user to be redirected to the example version of that page.
How do I do this using the web.Config file of my application? The reason I ask is that usually my web hosting provider has a tool in their back office that allows me to setup this redirect however, our client has opted for a different hosting provider that do not provide such a tool.
I have attempted to do this redirect using the following code but it doesn't seem to work:
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^test\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}}" redirectType="Permanent" />
</rule>
My application is an Umbraco powered site and so has several system.webServer entries in the web.config file. It may just be the case that I have entered this code in the wrong place but any help here would be greatly appreciated as I am only used to doing 301 redirects in .htaccess files.
This is not really that umbraco related but I think what you want to do is this:
<rewrite>
<rules>
<rule name="redirect" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Match all urls unless the host name part is exactly www.example.com - and redirect those to www.example.com/whatever.

Redirect DNN Portal Alias to a Specific Page of the Portal

I need to redirect requests to the root of a specific Portal Alias of a DNN 07.03.02 install to a page of that same portal. The redirection can only effect one portal alias, another portal alias on the same portal must not redirect the same. Also, the DNN install that hosts this portal has many other portals so I cannot force redirection via a meta redirect file in the site's root. I configured an IIS (8.5) rewrite rule, such as below, which technically does the redirection I want, but this breaks the relative path to all images and stylesheets which are located in the portal's root directory. I've also tried DNN SiteURL redirection rules but those fail to force any redirection at all. If any has any suggestions of how I can configure such redirection for a DNN portal I'd greatly appreciate it.
<rewrite>
<rules>
<rule name="my redirect" stopProcessing="true" enabled="false">
<match url=".*" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www.)?mysite.com$" />
</conditions>
<action type="Rewrite" url="/newpage" appendQueryString="true" />
</rule>
</rules>
</rewrite>
I corrected this issue by adding an exclusion to my IIS rewrite rule such as:
<add input="{PATH_INFO}" pattern="^/portals/0/" negate="true" />
so that the path to my portal's content would not be rewritten.