I have got links on my static website. These links are without .html extension.
https://zodoc.azurewebsites.net/posts/en/selective_blur - does not work
Error: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
https://zodoc.azurewebsites.net/posts/en/selective_blur.html - works fine
How to make it work without .html extension?
As rickvdbosch said, you could use URL rewrite to remove the .html extension in your URL.
Open the web.config and insert the following code inside the system.webServer node.
<rewrite>
<rules>
<rule name="RewriteURL" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.html" />
</rule>
</rules>
</rewrite>
Related
I noticed a lot of 404s in my logs which are seemingly being caused by an app/device automatically adding a slash to urls like http://example.com/folder/page.asp
So the url ends up looking like http://example.com/folder/page.asp/ which causes an error and 404 response.
This is on Windows Server 2019 running IIS.
I tried using UrlRewrite using code I found for a similar problem, but it doesn't change anything at all.
<rewrite>
<rules>
<!--To always remove trailing slash from the URL-->
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
</rules>
</rewrite>
I have the below config for url rewrite in my IIS
<rewrite>
<rules>
<rule name="Rewrite CI Index">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html|csv|ttf|woff|woff2|pdf|mp4|mov|ics" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(php_scripts)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/documents/intranet_documents/" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:0}" />
</rule>
</rules>
</rewrite>
The negate directive is there to prevent rewrite for website assets files (css, fonts, etc.) as well as other files from the documents upload/download section.
The issue I just came across is this, one of the urls is like this http://intranet/HR/Training-Basics however when I try to navigate to this url I get 404 because it is being caught by the negate function for file extension ics.
So, I need to be able to access this url, but at the same time I need to be able to download the "ics" files. What is the best way to do it?
You could modify the condition pattern from ics to\.ics, so that the rewrite rule will only rewrite based on file extension instead of specific string segment.
<rule name="Rewrite CI Index">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="\.(css|js|jpg|jpeg|png|gif|ico|htm|html|csv|ttf|woff|woff2|pdf|mp4|mov|ics)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(php_scripts)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/documents/intranet_documents/" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:0}" />
</rule>
I am working on an Angular2 app. It uses "#angular/common": "2.0.0-rc.4" and "#angular/router": "3.0.0-beta.2".
My problem is that when I use the browser refresh on some of the pages I see an error saying...
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
This also happens if I hit the url directly.
An example url is...
https://tilecasev2.azurewebsites.net/profile/therichmond
However if you view pages via the homepage they work ok but only until refreshed (https://tilecasev2.azurewebsites.net).
I have the below in my index.html head...
<base href="/">
Why does this happen and how can I fix it?
HashLocationStrategy avoids the issue by including a # in all of your angular routes but doesn't really fix it.
To make angular routes without hashes work in azure the same way they do in your local development environment, you just need to configure IIS to rewrite all requests as root. This lets angular handle the routing.
To do this, add a Web.config file to your site's root folder with the following contents:
<configuration>
<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>
</configuration>
If you deploying in same app service plan both angular and API project then this the solution.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="^/api" negate="true" />
<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></configuration>
for more details refer this link https://less0.github.io/azure-angular-II/
As Gunter pointed out HashLocationStrategy needed to be setup.
I followed the steps in the Angular2 docs and it all works now...
https://angular.io/docs/ts/latest/api/common/index/HashLocationStrategy-class.html
I have two virtual directories in an Azure Web App and confirmed that they're working properly as application directories.
The root of the Web App contains nothing except a web.config file with two rewrite rules that cause subdomains to point to subfolders like this:
<rule name="App1 Subdomain Redirect to SubFolder">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^app1.myservice\.net$" />
</conditions>
<action type="Rewrite" url="/app1/{R:0}" />
</rule>
<rule name="App2 Subdomain Redirect to SubFolder">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^app2.myservice\.net$" />
</conditions>
<action type="Rewrite" url="/app2/{R:0}" />
</rule>
(I understand this could be written more efficiently - I'm trying to remove as many variables as possible.)
In each of the virtual directories I have another web.config that contains a single rule to add an extension:
<rule name="Add Extension">
<match url=".*" negate="false" />
<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="{R:0}.ashx" />
</rule>
The problem I'm experiencing is that the "Add Extension" rule is never processed.
If I remove the rule from the virtual directory's config file and put it into the root's, all is well. (If I only do this for one virtual directory, it works fine for that directory while the other does not. If I do it for both, then all rules get processed.)
If I remove the "Add Extension" rule and try other rules the other rules do not get processed, which indicates to me this is not a problem specific to this particular rule.
If I remove all rules from the root's config, all rules in the virtual directories get processed.
My question is, has anyone else experienced this and what have they done as a workaround?
It's my understanding that rules should cascade from root to virtual directories in the same way other configuration settings do.
Searches have not been helpful.
Anand seems to have experienced the same problem on a non-Azure IIS site but no answer was proposed: http://forums.iis.net/t/1178488.aspx
Zielu1's question is somewhat similar but again did not receive a response: IIS URL rewrite in child virtual directory not redirecting
There are a fair number of other questions about rewrites, mostly about syntax and getting them to work in general, but few about virtual directory inheritance of rules.
Thanks for the help.
Try it matching full subdirectory paths
<rule name="Add Extension">
<match url="/MySubDirectory/.*" negate="false" />
<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="{R:0}.ashx" />
</rule>
How do i hide my page extension for example
mysite.com/index.asp
how do i take off the extension .asp
and also how i hide tables field names in a URL. example is I'm displaying details of a record of 2 . so the link is going to be
mysite.com/details?record_id=2
how do i take off the record_1d=2 to make it
mysite.com/details
I'm working with asp classic.
thanks
You want this:
http://www.iis.net/downloads/microsoft/url-rewrite
Your rule would look like this:
<rewrite>
<rules>
<rule name="RewriteASP">
<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="{R:1}.asp" />
</rule>
</rules>
</rewrite>
As far as I'm aware you can't rewrite the querystrings without retooling your code to pass data via HTTP posts.