MVC route to a Angular app in a virtual folder - asp.net-mvc

I have an Angular running inside a MVC app. It is set up as a Virtual folder inside the Web application on the IIS.
Currently I have a IIS rewrite rule so the Routing is handled by the Angular app. But this is causing some other problems so I like to find out if it can be done with the MVC routing?
So everything at ../app/[pathandquery] should be routed to the app/[pathandquery] folder

add this to webconfig
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>

Related

IIS web.config : Rewrite URL file as subdomain

I am trying to rewrite my url with a web.config file.
Actual URL: sudomain.mydomain.com/legal.html
Wished URL: legal.mydomain.com
I have already hide the html extension.
<rule name="Hidehtml" enabled="true">
<match ignoreCase="true" url="Legal" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="Legal.html"/>
</rule>
I saw this kind of rewrite is possible with subfolder, but I wonder if it is possible with a file.
I am trying this one but it give me a DNS error.
<rule name="testrule" stopProcessing="true">
<match url="legal(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="mydomain.com" />
</conditions>
<action type="Redirect" url="http://legal.mydomain.com" />
</rule>
I wonder if I am not missing something, maybe a redirect is needed too?
Thanks for your help !
To achieve this,
I just registered two CNAME for my website.
FQDN:subdomain.mydomain.com
FQDN:legal.mydomain.com
Then I apply them to my IIS site.
Just make sure both of them can be accessed in web browser.
Then I apply following rewrite rules
<rules>
<rule name="testrule" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^/legal\.[a-zA-Z]+" />
<add input="{HTTP_HOST}" pattern="subdomain.candy.com" />
</conditions>
<action type="Redirect" url="http://legal.candy.com" />
</rule>
<rule name="rewrite rule">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="legal.candy.com" />
<add input="{URL}" pattern="^(/)?$" />
</conditions>
<action type="Rewrite" url="http://subdomain.candy.com/legal.html" />
</rule>
</rules>
When you access sudomain.mydomain.com/legal.html, the request will be redirected to legal.mydomain.com/ and legal.mydomain.com will rewrite back to /legal.html for response content.
Please keep in mind that legal.mydomain.com is always required to be registered in DNS even you just use it as a mask.
If your website are forwarding the public internet, please remember to purchase domain for legal.domain.com as well.

Remove folder name in URL in Winhost

I have 2 domain names: domain1.com and domain2.com.
I am using the redirect script in the root to redirect each domain to it's own folder. This is working correctly. The problem I am having is that when it redirects to a folder it shows the folder name in the url after the domain name: (domain1.com/subfolder1).
My question is how to remove the ""subfolder1" from the URL?
I've tried to find a solution to this and found some guides out there but none seem to work. I have hosted nopcommerce in "subfolder1"
My web.config file as follows
<rewrite>
<rules>
<rule name="rule1" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain1.com$" />
<add input="{HTTP_HOST}" pattern="^www.domain1.com$" />
<add input="{PATH_INFO}" pattern="^/subfolder1/" negate="true" />
</conditions>
<action type="Redirect" url="\subfolder1\{R:1}" />
</rule>
</rules>
</rewrite>

Temphire (Angular) does not support deep links and refresh?

When playing with the Temphire app, I noticed that when I try to refresh a page by hitting F5, the application shows a blank page ! (ngViewport is not rendered)
Found the solution... it was an IIS issue, needed to rewrite urles in order to keep it working :
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>

IIS Rewrite even rewrites images/css/js - results in 404 not found

I am trying to rewrite the urls to make them search engine friendly
www.mydomain.com/qa/213/who-am-i
rewrites as
www.mydomain.com/qa/?qa=213/who-am-i
The below block works, but the problem is that the js/css/images urls inside the page are also rewritten. So the page looks for files like www.mydomain.com/qa/213/who-am-i/jquery.js which actually doesn't exist. So the page loads, but none of the css, .js and images work.
<rule name="CleanRouting" stopProcessing="true">
<match url="^qa/(.*)/(.*)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="qa/?qa={R:1}/{R:2}&{QUERY_STRING}" appendQueryString="false" />
</rule>
Please tell me how to fix this. I am using Asp.Net MVC (if it matters).
After several hours & days I finally found the correct IIS rewrite rule to be used for bypassing images/css/js etc files so that the page appear correctly.
The following rewrite rules must be added to your ASP.Net MVC project's Web.Config.
<!--Rewrite all paths containing a period like www.conceptworld.com/qa/453/who-am-i/qa-images/search.png to www.conceptworld.com/qa/qa-images/search.png -->
<rule name="RewriteFileUrls" stopProcessing="true">
<match url="^qa\/([^\/]*)\/([^\/]*)\/(.*[\.].*)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="qa/{R:2}/{R:3}" appendQueryString="false" />
</rule>
I am using the above rule plus the below 2 rules for the Question2Answer Question Answer PHP based solution similar to StackOverflow. I have installed Question2Answer on a Windows system with IIS + Asp.Net MVC.
<!--Rewrites urls like www.conceptworld.com/qa/tags -->
<rule name="RewriteSingleLevelUrls" stopProcessing="true">
<match url="^qa\/([^\/]*)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="qa/?qa={R:1}&{QUERY_STRING}" appendQueryString="false" />
</rule>
<!--Rewrites urls like www.conceptworld.com/qa/56/who-am-i -->
<rule name="RewriteTwoLevelUrls" stopProcessing="true">
<match url="^qa\/([^\/]*\/[^\/]*)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="qa/?qa={R:1}&{QUERY_STRING}" appendQueryString="false" />
</rule>
Just setting the above rules is not enough. What is most important is setting your base url in Question2Answer. I almost gave up and thought it was impossible to have pretty SEO friendly urls in Question2Answer when it is installed on Windows (IIS + Asp.Net MVC), until I discovered this setting. Thanks to Question2Answer developers :)
Go to Admin/Layout and set the base url like below:
Now you are all set to run Question2Answer along with IIS Asp.Net MVC.

IIS7 Url Rewrite - Redirect from {any}.aspx to {any}

I am converting my website from Asp.Net Webforms to Asp.Net MVC. I want to redirect all my old .aspx files to drop the .aspx. I run IIS7 with the Url Rewrite module installed.
Example:
/about.aspx -> /about
The user will go to http://www.site.com/about.aspx and I want them redirected to http://www.site.com/about.
How do I do this using Url Rewrite? I don't want to have to do to each .aspx and put a meta-redirect in.
In your web.config file in system.webServer configuration section add:
<rewrite>
<rules>
<rule name="WebFromsToMVC" stopProcessing="true">
<match url="^(.*?)\.aspx\?*?.*$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}" />
</rule>
</rules>
</rewrite>

Resources