I need to remove WWW. from all my URLs on route 53. I have a web.config rewrite rule on my website that works with my Azure VMs but when converting to webapps it is not allowed. A mistake in the past informed users that their personal website was www.john.domain.com or www.jane.domain.com. With the Rewrite rule on it works going to VMs in azure but not to Webapps. I am looking to remove the extra www. from all url requests. I am using Route 53 for DNS and I have a Redirect rule for Naked DNS domain.com already to go to www.domain.com but I would like to have another redirect or rewrite that works like the web.config rule.
<rule name="Remove www from 4th level" stopProcessing="true">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.([^\.]+\.[^\.]+\.[^\.]+)$"/>
</conditions>
<action type="Redirect" url="http://{C:1}/{R:0}" statusCode="200" statusReason="Ok"/>
</rule>
You're missing the http/https from your pattern. Your conditions should look more like:
<conditions>
<add input="{HTTP_HOST}" pattern="^http://www\.([^\.]+\.[^\.]+\.[^\.]+)$"/>
<add input="{HTTP_HOST}" pattern="^https://www\.([^\.]+\.[^\.]+\.[^\.]+)$"/>
</conditions>
Related
I have a rewrite rule that redirects users from mydomain.com/reset/test123 to mydomain.com/module.aspx?key=test123.
The rule works fine, and look like this:
<rule name="Reset" stopProcessing="true">
<match url="^reset/([_0-9a-z-]+)" />
<action type="Redirect" url="/module.aspx?key={R:1}" appendQueryString="false" />
</rule>
The only problem is that my website has multiple domains, and the rule runs for all of them. I need the rule to only run for mydomain.com.
I tried to change the match url to ^mydomain.com/reset/([_0-9a-z-]+), but this don't work.
How can I make the redirect to only run for one spesific domain?
Just add a condition under your <rule> element:
<conditions>
<add input="{HTTP_HOST}" pattern="mydomain.com" />
</conditions>
See Documentation
I have subdomain with an A record to my IIS Server:
sub.domain.com
The IIS server has a binding for sub.domain.com and a cert for *.domain.com
What we need is when someone goes to sub.domain.com it takes them to another site but masks the URL and keeps the SSL. The destination page has in its SAN cert sub.domain.com.
Tried a forward on Godaddy which works but it doesn't keep the SSL and we get cert issues. So thought was to point to our server to pass SSL and then redirect it. I tried a URL Rewrite but it's giving a 404.
URL Rewrite:
<rewrite>
<rules>
<clear />
<rule name="Pay Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?sub\.domain\.com$" />
</conditions>
<action type="Redirect" url="https://www.domain2.com/cgsdesktop/PaymentLanding/UniversalPortal" appendQueryString="false" />
</rule>
</rules>
</rewrite>
I just need to know how to get this done.
How about this:
<rules>
<rule name="Pay Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^sub.domain.com$" ignoreCase="true"/>
<add input="{HTTP_HOST}" pattern="^www.sub.domain.com$" ignoreCase="true"/>
</conditions>
<action type="Redirect" url="https://www.domain2.com/cgsdesktop/PaymentLanding/UniversalPortal" appendQueryString="false" />
</rule>
</rules>
use sub.domain.com instead of sub\.domain\.com.
This article contains some useful recipes on IIS redirect/rewrite rules.
In order to mask the URL and keep the SSL in the browser bar, we need to create URL Rewrite action rules of URL Rewrite extension.
However, URL Rewrite action only supports to redirect the request to the same domain by default. We have to install the Application Request Routing extension when redirecting the request to another website.
https://www.iis.net/downloads/microsoft/application-request-routing
or we will get an Http 404 error.
See my preceding post for more details.
ASP.net URL Rewrite subdirectory to external URL
Feel free to let me know if there is anything I can help with.
we have a site at something.example.com and we want it to go always redirect to www.example.com
We already have the rule in for 'adding' www. when a user just puts example.com.
But we have a test url that is in place for other reasons and we want the live site to ALWAYS redirect to www.example.com no matter what prefix it has before the domain.
just use this regex .* in <match url="" /> or IIS URL re-write pattern field
for additional information:
dot means any single char
Asterix means zero or more of a char
so .* means zero or more of any char
According to your description, I suggest you could try to use {http_host} to match the domain part in the url rewrite rule.
Details, you could refer to below rules:
<rule name="rediect" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(.*).example.com" />
<add input="{HTTP_HOST}" pattern="^example.com" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" />
</rule>
To try and make this as short as possible, I have two domains at work.
The first domain is our main domain at www.site1.com (port 80), pointing to a regular set up of a site in IIS 8, Server 2012.
The second domain is at www.site2.com (port 8085), but using some clever URL rewrite wizardry that I found on SO, www.site2.com points to www.site1.com/site2/, but behaves as if it were it's own domain. We did this in order to share assets between site1 and site2 in a .NET environment.
I do not have DNS-level control, but have admin of the server and it's settings and have done all of the URL rewriting for both sites myself. We received a request to install an SSL cert on www.site2.com (port 444) so that we can set the site to HTTPS. This is not relevant to the problem in itself because the problem exists in HTTP already.
The problem came about because another developer wants to be able to test the cert and the port configurations. As of right now, this isn't possible even in HTTP. Typing in www.site1.com:80 on the server works fine, but www.site2.com:8085 does not. site2 only connects properly when appended with www.site2.com:80 or just by typing in www.site2.com, I believe since it is rewritten as a subfolder off of site1.
I have tried everything I could think of in order to try and rewrite the ports in the URL so that the developer is able to test the port configuration by typing in www.site2.com:8085. The URL never resolves.
The bindings are set correctly as well because www.site2.com works fine in both test and production and has for years. It only does not work when the correct port is added to the URL.
This is the only code triggering the rewrite as it stands:
<rule name="www.site2 redirect" enabled="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www.)?site2.com$" />
</conditions>
<action type="Rewrite" url="/site2/{R:0}" />
</rule>
Any and all help would be appreciated. Thanks.
You can do that in this way, just add one more condition into your rewrite rule:
<rule name="www.site2 redirect" enabled="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www.)?site2.com$" />
<add input="{HTTP_HOST}" pattern="^(www.)?site2.com:8085$" />
</conditions>
<action type="Rewrite" url="/site2/{R:0}" />
</rule>
Another way to to that with one condition is (remove $ from pattern in condiiton):
<rule name="www.site2 redirect" enabled="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www.)?site2.com" />
</conditions>
<action type="Rewrite" url="/site2/{R:0}" />
</rule>
But this rule will capture domains like that as well: site2.com.au, site2.com.fr, site2.com:{ANYPORT} etc. That's why i prefer first rule
I have to redirect from a domain to another.
I try different ways to do this but it doesn't work.
Someone can tell me the right metod to do a redirect in web.config?
Without knowing the ways you tried, I would suggest setting up a Global URL Rewrite rule, you do this at the server level not the individual web site level.
These setting will be stored in the applicationhost.config (Server level), not the (web.config)
Below will redirect example2.com to example.com
<rule name="Redirect to new domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^example2\.com$" />
</conditions>
<action type="Redirect" url="https://www.eample.com/{R:0}" />
</rule>