IIS 7 set default page for the whole site - iis

I have followed the instruction reported here :
https://www.c-sharpcorner.com/UploadFile/francissvk/set-default-page-for-a-website-in-iis421/
What i would like to achieve, is that when user try to visit my site : "https://mysitename.com" it should be redirected to the home page ( "https://mysitename.com/pages/home.aspx").
I don't want to create a root Default.aspx page only to do the redirect, i would like to achieve this behaviour through Web.config.
As said, i tried the instruction in the above link, buy also tried the many solution proposed on this site that more or less suggest to add this configuration to Web.config :
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear />
<add value="/Pages/Home.aspx"/>
</files>
</defaultDocument>
<handlers>
I have tried different variation of the path, i have tried :
<add value="/Pages/Home.aspx"/>
<add value="~/Pages/Home.aspx"/>
<add value="./Pages/Home.aspx"/>
<add value="Home.aspx"/>
But allways i get this message error :
403 - Access denied.
If i manually enter in the browser the full page url "https://mysitename.com/pages/home.aspx" then i get no issue (just to point out that the page exists and is working)
I don't understand what i am missing in the configuration

A default page or DefaultDocument in IIS can't do what you want.
It is a feature that defines which document is loaded when a user requested a URL pointing to a directory on the server without specifying an actual page.
The value field should be the name of a file in that directory such as index.html or home.asp, it can not point to files in other directories.
In your case you may be able to use the builtin HTTP Redirect feature, in the GUI enable it and point to 'pages', also check the Only redirect requests to... checkbox
In your root web.config this may look like this:
<system.webServer>
<httpRedirect enabled="true" destination="pages" childOnly="true" />
<defaultDocument enabled="true">
<files>
<clear />
<add value="Home.aspx"/>
</files>
</defaultDocument>
</system.webServer>
Another option is to use the IIS Rewrite Module which allows you to create more complex rules on how to redirect and rewrite requests. It should be faster because it does work without a HTTP redirect which does back to the browser, but you first need it install it and understand how to use it.

Related

URL Rewrite Redirection

I have configured a website in IIS with a virtual directory. (applicationHost.config file is given below )
<application path="/" applicationPool="TestMovieSearch">
<virtualDirectory path="/moviesearch" physicalPath="C:\inetpub\wwwroot\fullmovielist" />
</application>
I am using URLRewrite to redirect user to a specific html page. I have the below webconfig file placed in this path.
Path : C:\inetpub\wwwroot\fullmovielist
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Catch all for movie search redirection">
<match url="/" negate="true" />
<action type="Rewrite" url="/MovieSearch/action/movies.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
When I tried the URL http:\localhost\MovieSearch, its properly getting redirected to movies.html page. I just need to know how the web.config file matches with virtual directory and
properly redirect to movies.html page.
Note: I am a newbie to web.config file. So any help would be appreciated.
According to my understanding, you don’t need a rewrite rule, but you want to know how this rewrite rule works, is that right?
I guess there is also an action folder in your fullmovielist folder, which contains movies.html. (If not, it is the application of the MVC structure you are using.)
If you want to know how the url matches the rule and rewrites to new one, it is better to use fail request tracing.
http://localhost/moviesearch,the part of "/moviesearch" match the "/" and rewrite to http://localhost/moviesearch/action/movies.html.
You can know more rules and ways about url rewrite from document.

IIS reroute just one site to Apache

I'm trying to figure out how to reroute just one of our sites from IIS to Apache. I've followed several online tutorials and posts and nothing is working. I keep getting:
I've read that I need to do a reverse proxy using the URL Rewrite feature of IIS. So I did that and here are my settings:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="false" destination="" />
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:8088/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Apache is on 8088 and if I hit localhost:8088, it works just fine. I've also added IUSR and IIS_IUSRS users to the directory permissions both having read and execute, list contents, and read permissions. I wouldn't think this would be that terribly hard.
When you need to rewrite IIS to apache, please remember to install ARR.
https://www.iis.net/downloads/microsoft/application-request-routing
Then please remember to enable Server node->application request routing cache->Server Proxy setting->Enable proxy.
Besides, could you access orchestrator.local without URL rewrite rule. Because, if this issue is caused by IIS, you should receive status code more than site can't be reached.

How can I configure IIS to serve directories without trailing slashes and always serve relative to root path?

I have a single page app hosted in IIS and I want make sure all requests are directed to /index.html (which will interpret the url and handle all routing client side). The only exception to this rule is when the request is for an actual file that is on disk such as *.js, *.css, *.png, etc. (I still need to be able to load the app after all ;-). Nearly everything works correctly with the following web.config file:
<configuration>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404"/>
<error statusCode="404" responseMode="ExecuteURL" path="/index.html" />
</httpErrors>
</system.webServer>
</configuration>
If I request mydomain.com/contact the /index.html page is served as expected, but if I request mydomain.com/contact/ (note the additional trailing slash) then all the relative paths in my app blow up because the browser tries to load /contact/some-file.js instead of /some-file.js. I can fix this by making all my paths rooted, but for more reasons than just inertia I want to be able to stick with relative paths.
The second related issue occurs when there is a directory on disk matching the requested url. For example, if I request /services and there is a /services directory on disk then the request is automatically changed to /services/ (I think IIS is the culprit here) which then produces a 403 error response because IIS rightfully refuses to serve up the directory contents.
Note that adding this to web.config partially solves the second problem:
<remove statusCode="403"/>
<error statusCode="403" responseMode="ExecuteURL" path="/index.html" />
Partially because it causes the 403 failure to use /index.html for its response but the rest of the resources are loaded relative to /services/ instead of / (which is back to the first issue with relative paths above). Also it is partial because a request to /services is still getting changed to /services/.
So my question is how can I prevent paths like /services from being changed to /services/ when there is a matching directory on disk and how can I make all redirects serve the response from the root and leave all path routing to the client (that is to treat a request for /contact/ as if it were a request for /contact)?
Update:
This seems to describe the problem accurately:
https://support.microsoft.com/en-us/help/298408/iis-generates-courtesy-redirect-when-folder-without-trailing-slash-is
I am using IIS 10 but the behavior is the same.
The 403 status code is for 'Forbidden' because the directory listing is correctly denied so adding this to web.config is treating the symptom and not the cause. I tested adding 301 and 302 to web.config and IIS does not allow this and produces the error:
The 'statusCode' attribute is invalid. Integer value must be between 400 and 999 inclusive
According to:
https://forums.iis.net/t/1153462.aspx?Is+it+possible+to+disable+the+courtesy+301+redirect+for+URL+requests+that+lack+a+trailing+slash+
there is no built in way to change the 301 behavior in IIS, and using url rewriting is the only way to deal with this. So I installed the IIS URL Rewrite Module (https://www.microsoft.com/en-us/download/details.aspx?id=47337) and added this to web.config instead:
<rewrite>
<rules>
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
</rules>
</rewrite>
Now all requests with a trailing slash get it removed, IIS no longer performs 301 redirects to add back the slash, the client side loads resources are loaded relative to the root (thanks to no trailing slash), and the client side routing takes over and loads the correct content.

I can't access my website from outside Windows Server 2012 using IIS and IISNode

I bought a new dedicated server. I have a MEAN Stack application (Node.js, Angular, MongoDB, Express) and wanted to take advantage of using IIS to publish my webapp.
I followed this guide to install iisnode and make a litle node.js server working.
I did it and succesfully tried http://iisnode.local in my browser inside the server.
Ont he other hand, if I try http://(theIPoftheserver)/iisnode.local am I am getting the following error:
I need to do something for the server to be accesible from outside but I don't know what..
If i go to http://(theIPoftheserver)/ I can see IIS website and even if I go to http://(theIPoftheserver)/node I can see the iisnode website...
I am quite newbie and I need some help...
My web.config file:
<configuration>
<system.webServer>
<!-- indicates that the server.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="sendToNode">
<match url="/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
<iisnode enableXFF="true" />
</system.webServer>
</configuration>
EDIT: I also have to mention that I have a new rule in windows' hosts file as follows:
127.0.0.1 iisnode.local
EDIT2: can windows firewall be blocking something? Do I need to disconnect it?
IMPORTANT EDIT 14.09.2016: if I edit hosts file and add:
<server-ip-address> iisnode.local
And then I the I visit http://iisnode.local it works!
I don't understand it very well why though.. i don't want all the users of my website to modify their hosts file, what can I do?
I don't know is this could be the source of the problem?
EDIT: My Website bindings look like this:
When you access your site within the server with
http://iisnode.local (by hostname)
It is same as
http://127.0.0.1/ (by IP)
So when you use IP address, you don't put iisnode.local after it.
iisnode.local is hostname, in an URL, you either use hostname OR IP, not the same time.
http://(theIPoftheserver)/iisnode.local
is equal to
http://(IP)/(hostname) <--- That is wrong!
Currently, I am assuming you don't have public dns setup for your server, the correct way to access the site will be
http://(External-IP)/ <-- No iisnode.local after it.

How can I get IIS to redirect to a virtual application if no path is specified?

My IIS setup has one site, bound to a domain. Let's call it: www.mydomain.com
The site folder itself is empty. This site hosts multiple applications and virtual directories. One of the applications is 'portal'.
What I want to do is accept any incoming request for www.mydomain.com or www.mydomain.com/ and redirect it to: www.mydomain.com/portal
I've got ARR and URL Rewrites up and running. I'm just not sure how to configure them for this.
A redirection rule like below will work.
Put the following web.config file to your web site's root folder. Or, update the existing one if you have.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="toPortal" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/portal" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You may want look at this tutorial to learn how to create url rewrite rules with IIS Manager. These xml nodes are not coming from my brain too.

Resources