IIS URL re-write - iis

I have an intranet hosted on an IIS server (Windows Server 2016) which I want to run over https. On our internal web server I have set up a Host (A) record:
Host - intranet
FQDN - intranet.mydomain.co.uk
IP address - xxx.xxx.xxx.xxx
I have applied a certificate to the IIS server and set up the bindings and it loads fine. However previously people could access the intranet through an Alias (CNAME) record - i.e. http://intranet
and I am worried that they will grumble about the longer URL.
Is there a way of setting something up so if you type in https://intranet then what you are seeing is https://intranet.mydomain.co.uk and not get any certificate errors. I am wondering if I can do something with DNS, URL masking or URL re-write.
All suggestions welcome!

I was able to solve this in the end by installing URL Rewrite on IIS then adding a rule:
Requested URL - matches the pattern
Using - regular expressions
Pattern - .*
Ignore case - ticked
Conditions - {HTTP_HOST} | Matches the Pattern | intranet
Action type - redirect
Redirect URL - https://intranet.mydomain.co.uk/{R:0}
Append query string - ticked
Redirect type - permanent (301)

Related

How to setup a reverse proxy in IIS using host file?

I'm trying to setup a reverse proxy in IIS 10 using some fake urls.
In my host file I set up :
127.0.0.1 somedomain.com
Then I created a website in IIS 10 binding to this domain and a fake page :
When typing somedomain.com on chrome, the fake page shows properly. I assume the fake domain website works.
I have then another website with a reverse proy rewrite rule. I expect requests to the new website to be rewritten and show the first somedomain.com
When running my reverse proxy website I'm getting the error :
HTTP Error 400.605 - Bad Request
The request cannot be routed because it has reached the Max-Forwards limit. The server may be self-referencing itself in request routing topology.
Does anyone know what I'm doing wrong please ?
I tried changing the rule action type to "Redirect" and I can see that the redirection works correctly.

IIS URL Rewrite for a folder to another web server

I have an IIS webserver running a website. I've installed ARR3 to enable routing rules.
I'd like to redirect all the incoming request for the URL .mydomain/url2redirect/ to an Apache server installed on the same machine where is running SVN.
So in the inbound rule definition I've inserted the following:
Input: URL path after '/'
Pattern: *.mydomain/url2redirect/*
Action Type: Rewrite
Action URL: https://ip-address:8080/{R:2}
By testing the pattern, I get the desired result, and in the R:2 back reference I get the requested page I need to pass to SVN, but I get always a 404.
"url2redirect" doesn't exist but it should captured by the URL rewrite and forwarded to the Action URL.
I've added any outbound rule. Should I have to add something? what?
I've tried also to add a Reverse Proxy Rule, using the ARR template but, it's completely ignored, therefore I think that the routing is not working at all on IIS.
As far as I know, the url rewrite rule Pattern doesn't match the domain part.
That means mydomain will not include in the Pattern.
If you want to match the url2redirect, you should use below pattern.
url2redirect(.*)
Then I suggest you could modify your action url as below:
https://ip-address:8080{R:1}

IIS URL Rewrite - how to see rewritten URL?

In IIS I've set up a basic URL Rewrite with an Inbound rule to perform a Rewrite action to another domain:
Pattern match: ^somedirectory/(.*)
Action type: Rewrite
Rewrite URL: http://www.google.com/{R:1} (using google just as a test)
The problem is, how can I actually see what the server has rewritten the URL to? When I check the IIS logs (I have "Log rewritten URL" option ticked), I would expect to see www.google.com somewhere - but it's nowhere to be found.
The pattern is definitely matching because I get the error: "502 - Web server received an invalid response while acting as a gateway or proxy server."
How can I see what is going on behind the scenes (how IIS has changed the request)?
One way is to enable "Failed Request Tracing" is IIS.
For the status code choose a range like 100-999 to capture all requests (even non-failing).
IIS will create an XML file for each request to a log directory. The XML can be viewed nicely within Internet Explorer (try the compact view tab).

SSL-Certificate for www and www-free within Plesk and Plesk Admin Panel

I've got the following problem. We have a SSL-certificate for a domain with a prepended 'www', like 'www.test.com'.
I've integrated that certificate with Plesk for this domain and it works fine, when somebody goes directly to 'www.test.com'. But when I enter only 'http://test.com', he won't recognize the certificate and shows a warning. How can I prevent this? Do I need an extra certificate (hope not) or can I redirect the domain within Plesk directly. A PHP-header isn't enough, because the redirection would take place after the browser tries to establish the ssl-connection.
And because the Plesk admin panel runs on this same domain, we have the same problem with 'http://test.com:8443' …
So basically:
'https://www.test.com' - fine
'https://test.com' - not working
'https://www.test.com:8443' - fine
'https://test.com:8443' - not working
Any suggestions would be nice, thanks a lot,
Carl
Try adding a this rule to .htaccess in the public root. It should redirect from test.com to www.test.com for SSL connections:
RewriteRule ^/(.*):SSL$ https://www.test.com/$1 [R,L]
Learn more about htaccess redirects
Typically, the certificate needs to be purchased for specific subdomain. Some Certificate Issuers do offer a cert for the .test.com domain that includes all subdomains (including test.com and www.test.com). If you're unsure, you should contact your certificate issuer directly.
Well first what plesk version with which OS you have, It's Linux or windows if Windows to Add reWrite URL in IIS setting on under particular.
If you have Linux with plesk any version because it's not matter either you have plesk or cpanel.
with Linux
Add ReWrite module in .htaccess for domain purpose only not for access plesk panel with specific port 8443
8443 port only configured with plesk shared license.
Use follow to avoid Trusted message
https://www.test.com - fine
https://test.com' - not working
in this case use URL rewrite redirection as above said steps.
=============================
Check Cname Entry in particular domain DNS record.
I hope this helps.

Is there a way to always require or force the 'www' subdomain on a site?

I want to prevent users from going to say example.com and only go to www.example.com, we are using IIS 6. So say they go to example.com it could tack on the www.example.com, etc.
Is this a setting somewhere or will I have to code it to check for the subdomain when they land and redirect accordingly?
EDIT: I know the best way is to move away from the www prefix but for whatever reason if the user launches a course (this is an LMS) without the www in the URL the tracking does not work for the .asmx file, that is why I am trying to force the 'www' because if some people don't have it then they wonder why the tracking does not work.
If you're using ASP.NET create an HttpModule, handle the BeginRequest event and add this code inside your handler:
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
if (context.Request.Url.Host == "example.com")
{
context.Response.Clear();
context.Response.Status = "301 Moved Permanently";
context.Response.AddHeader("Location", "http://www.example.com" + context.Request.RawUrl);
}
Note that I didn't use Response.Redirect(), this is done for the sake of SEO, as Response.Redirect() always returns status 302 which means the object was moved temporarily while status 301 means the object was moved permanently, this will keep the PageRank of your pages from being divided between the www and the non-www versions (if search engine crawlers can access the page using both the www and the non-www URLs, they will divide your PageRank between the two, hence is the use of 301 which search engine crawlers understand and will keep your PageRank to only the www version of your site).
As both records already point to the correct server...
...you could simply set up a new website in IIS (server version needed) and have it respond only to example.com (the host header setting) and have it redirect to the wanted url (check redirect to url in Home Directory tab and enter www.example.com). The original site should then handle it (you could set it's host header to answer to www.example.com to be more specific).
If you can't do that on the web server, your publishing firewall should be able to, or you might consider replacing it. Your DNS provider might also provide (pun not intended) a redirect service (doing basically the same thing as above for you I guess).
As per other responses, arrange for a 301 redirect from the unadorned domain name to the site with the www. prefix.
Given that I actually work in the DNS industry, I'd like to share my views on the www. debate:
For now, at least, IMHO, the preferred version of URLs should be with the www. prefix. The hostname part of a URL is exactly that, it is a hostname. The only DNS resource records that your browser will search for are A (and possibly AAAA for IPv6) records, and the resulting IP address is that which it'll connect to.
It is not a web site address - only the full URL (with the http:// prefix) specifies that this host is expecting to receive HTTP connections on port 80.
The whole reason for the www. prefix in the first place was to allow for the separation of different protocols to different hosts. As Verisign showed when they (briefly) introduced their "SiteFinder" service several years ago, assuming that every request for an A record is for the use of the HTTP protocol is a massive mistake.
Having the canonical version of your URL be the one with the www. prefix also makes cookie handling easier, and allows for easier splitting of static content to content delivery networks (as recommended by Yahoo!, Google, etc).
Now, there is a DNS record type (SRV, see RFC 2782) which uses a service and transport prefix to allow a single domain name to dispatch different protocols to different hosts (and hence IP addresses).
The ideal DNS set up would be a record that looks like:
_http._tcp.example.com IN SRV 10 0 80 www.example.com.
This says that all requests for HTTP URIs over TCP/IP should be addressed to TCP port 80 on the hostname www.example.com. Note that with this syntax you could also have HTTP services automatically server from ports other than port 80 without the port number being part of the URL.
The SRV record is a required part of SIP, and is commonly used for Jabber (XMPP). However AFAIK no browser uses it. :(
Contact your host (or your domain registrar) and have them set it up to work with or without www. It should however work both ways or only one way if you so wanted. I'm assuming you have a host and are not running your own web server/domain name registration, lol.
This is how it works, regardless of whether or not you should.
This is handled by DNS. Usually, example.com and www.example.com will point to the same server, but they don't have to. If www.example.com isn't explicitly registered, then the request gets sent to the example.com server, and that server gets to decide what www.example.com means, as well as mail.example.com, ftp.example.com, home.example.com, users.example.com, and so on.
Edit: I realize this story is sort of incomplete, as these days Apache gets handed the URL that you used to get in with, and it may interpret a subdomain from that, and direct the request to a virtual site. But this shouldn't be a factor at the "www" level.
The typical way this is done by web sites is to do an HTTP redirect from example.com to www.example.com. You do this by returning either HTTP Status code 301 (permanent redirect) or 302 (temporary redirect) when user goes to example.com, and setting the HTTP location: field in the response to http://www.example.com. Google for "301 versus 302" to see when you should use either.
Note that this is an HTTP feature, not something provided by DNS... some domain name providers however do provide HTTP redirect facility for you if you use their name servers.
Note you can test this out for yourself. Go to http://web-sniffer.net and type yahoo.com (or microsoft.com or any major web site). You'll see that they respond to a redirect with the www version of the name (in less common cases some web sites go the other way, redirect www to the non-www version of the name).
When I had the misfortune to work on Microsoft's web stack, I used ISAPI_Rewrite to force www. prefixing (among other things).
At my web site I just put the following into the .htaccess file:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^tafkas\.net$ [NC]
RewriteRule ^(.*)$ http://www.tafkas.net/$1 [L,R=301]
For Apache based server you can use this code
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$ [NC]
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
Explanation: The first line just turns the rewrite engine on. The second line of code is to check the url entered by the user. The bash sign (!) means not equal to. The carrot sign (^) means the beginning of the statement to be checked. Backslash dot (.) refers to the special character of dot, which when used without backslash means 'anything'. The dollar sign at the end of the statement refers to the end of the url. The third statement states that if the input given by the users is not the one as given in statement two, then proceed as follows. (.*) means that anything and any number of times. This is used so as the save anything written by the user after yourdomain.com/ gets stored in the variable $1. R=301 refers to the permanent redirection, and L states that this is the last in the series of status codes.
As stated adding the WWW is the opposite direction to be going. WWW is a redundancy these days.
You can check out http://no-www.org/ for further information.
This is actually backwards. It was how they did it in 1998, but now you're supposed to if anything drop the www.
Also, example.com is specifically reserved for posting example urls. Someone probably actually owns and uses the one you provided. How do you know you're not pointing someone to a porn or malware site with that random example?

Resources