IIS 10: Serve file with same name as directory - asp.net

I've just set up a IIS server, and made a simple website. I have a file called "image.aspx" and a directory called "image" and I have URL Rewrite 2.0 to not need the .aspx. When I see domain.com/image i get a no permission 403, but when I visit domain.com/image.aspx it shows. How can I make it that when you visit domain.com/image you go to domain.com/image.aspx but you are able to go to domain.com/image/file.aspx?

We just check if the file with the request URL name exists then make a redirection. Moreover, the specific file under that directory is accessible too.
<rules>
<rule name="MyRules" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{DOCUMENT_ROOT}{Request_URI}.aspx" matchType="IsFile" />
</conditions>
<action type="Redirect" url="Https://vabqia969vm:448{request_URI}.aspx" />
</rule>
</rules>
</rewrite>
Feel free to let me know if the problem still exists.

Related

images and css are not downloading for iis url rewrite

i am running my site from VS2013 IDE
i have include country code in url by http module like http://localhost:53741/gb/
but there is no folder called gb. so i suppose to get error. just to by pass that error i copy iis url rewrite rule in my web.config file. here it is
<rule name="Rewrite rule for Redirecting countries" stopProcessing="true">
<match url=".*" />
<conditions trackAllCaptures="true">
<add input="{REQUEST_URI}" pattern="[a-z]{2}/(.*)" />
</conditions>
<action type="Rewrite" url="/{tolower:{C:1}}" appendQueryString="false" logRewrittenUrl="true" />
</rule>
now the above url works but js and css file not downloaded. i checked with developer tool and js/css files path are ok.
my css is in content folder in root folder and js is in scripts folder. when i check the url of js and css then i found those was ok but files do not downloaded.....do not understand why?
here is developer tool screen shot
just see the file path from picture above. that is right.
i use this rule
<rule name="Some rule">
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="^.*\.(ashx|axd|css|gif|png|jpg|jpeg|js|flv|f4v)$" negate="true" />
</conditions>
</rule>
but still no luck.what causing problem.anyone can help me to figure out this issue. thanks

HTTPS redirect to a folder not working

I just installed https certificate and am having a hard time setting up redirect.
I tried using HTTP Redirect in IIS (7.5) but can't get it to work in IE and in FF and Chrome once I pass the initial login page, I get "Too many redirect" error.
I also tried URL Rewrite but it was total failure so i reverted to HTTP Redirect.
Users used to access the site using "http://example.com/internal". Now, i want to redirect this to "https://internal.example.com/internal" and can't get it to work. I would much prefer not to use the last "internal" in the URL, if possible (the Common Name I used when requesting CSR was internal.example.com).
In HTTP redirect, I set "Redirect requests to this destination" to "https://internal.example.com/internal/default.aspx" and set "Redirect behavior" to "Only redirect requests to content in this directory" with Status Code 301 (Permanent).
Web site has an "internal" folder that contains the .Net application files and requires form authentication. The files in root folder are open to all (i.e. www.example.com is open to all).
Any help you can provide setting this up is greatly appreciated.
Update
I updated web.config and added some URL Rewrite rule but still not quite there.
In IE, when I type example.com/internal it goes to https://internal.example.com but not http://internal.example.com/internal.
In Chrome, it doesn't go to https, stays in http and shows "Not secure".
<rewrite>
<rules>
<rule name="Rewrite to internal" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.example.com$" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="internal.example.com to sub folder internal" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^internal\.example\.com$" ignoreCase="false" />
<add input="{PATH_INFO}" pattern="^/internal($|/)" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/" />
</rule>
</rules>
</rewrite>
The first rule is to just let http://example.com go through; the second is to redirect http://example.com/internal to https://internal.example.com/internal.
Check your Authentication applet in IIS. it should allow anonymous auth.

W3 Total Cache IIS minify error

My Problem
I am getting an error trying to minify URLs using the Wordpress plugin W3 Total Cache with IIS.
W3 Total Cache error:It appears Minify URL rewriting is not working.
Please verify that the server configuration allows .htaccess
Unfortunately minification will not function without custom rewrite
rules. Please ask your server administrator for assistance. Also refer
to the install page for the rules for your server. Technical info
.htaccess file contains rules to rewrite url
http://myurl.com/:\Web\Public_Test2/wp-content/cache/minify/000000/w3tc_rewrite_test.
If handled by plugin, it returns "OK" message. The plugin made a
request to
http://myurl.com/:\Web\Public_Test2/wp-content/cache/minify/000000/w3tc_rewrite_test
but received: Connection timed out after 2016 milliseconds instead of
"OK" response.
(note: I edited the domain name for privacy) I find the URL to be quite odd having the domain in there but I do not know how to change the default URL it tests. If coming from the main directory it is indeed Web/Public_Test2/wp-content/cache/minify but there is no 000000 folder in there.
W3 Total Cache Recommendations
Under the install tab for the plugin there is a note for people not using apache:
In the case where Apache is not used, the .htaccess file located in the root directory of the WordPress installation, wp-content/w3tc/pgcache/.htaccess and wp-content/w3tc/min/.htaccess contain directives that must be manually created for your web server software.
However, a w3tc folder does not exist, only a w3tc-config folder which has a master.php and master-admin.php file, no .htaccess or subfolders. I checked a cache folder under wp-config and there is no .htaccess in any subfolder. So I am not sure how to change the web.config or with what directives.
My Attempt
I found somewhere suggesting that these rewrite rules be added to web.config, I added them but it did not change the error at all:
<rule name="w3tc_rewrite_test" stopProcessing="true">
<match url="^wp-content/cache/minify/000000/w3tc_rewrite_test" />
<action type="Rewrite" url="wp-content/plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1" logRewrittenUrl="true" />
</rule>
<rule name="w3tc-minify-test-file" stopProcessing="true">
<match url="wp-content/cache/minify/(.+/[X]+\.css)$" />
<action type="Rewrite" url="wp-content/plugins/w3-total-cache/pub/minify.php?test_file={R:1}" />
</rule>
<rule name="w3tc-minify-file" stopProcessing="true">
<match url="wp-content/cache/minify/(.+\.(css|js))$" />
<action type="Rewrite" url="wp-content/plugins/w3-total-cache/pub/minify.php?file={R:1}" />
</rule>
I ran into the same issue and here is the solution that worked for me:
W3 Total Cache: Version 0.9.4.1
Wordpress: Version 4.5.2
IIS: Version 7.5
Server: Windows 2008 R2
My web.config has these rules:
<rewrite>
<rules>
<clear />
<rule name="w3tc-minify-file" stopProcessing="true">
<match url="wp-content/cache/minify/(.+\.(css|js))$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="wp-content/plugins/w3-total-cache/pub/minify.php?file={R:1}" />
</rule>
<rule name="wordpress" enabled="true" patternSyntax="Wildcard">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
When I put the w3tc-minify-file rule under my wordpress rule, it did not work and I was getting 404 errors on all of the minify files W3TC was creating.
I'm using manual mode minify and just combining my css and js files and it's working great. Hope it helps someone.
The chances of this working with the auto minify mode are very low, so I definitely recommend doing the manual mode for the highest chance of success. I had 3 JS files and 2 CSS files I could not combine/minify because they broke my site. Manual mode gives you the most control, so spend a bit of time adding each file until you have it as best as you can.

Remove Trailing Slash From the URL

I want to redirect "abc.aspx/" to "abc.aspx". How can this be done?
Page gets broken when requested page ends with '/'. How to handle such type of requests?
Is there any rewriting rule that can be added into web.config file?
In your web.config, under the system.webServer, add
<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>
Some Gotchas
In your development environment, if you run your web site under Visual Studio Development Sever, you won't be able to see this feature working. You will need to configure your application to run under at least IIS Express.
When you deploy your web site and see that this feature is not working on your production server, it will be because you miss configured something. One of the common mistakes is having overrideModeDefault attribute set to Deny for rules under <sectionGroup name="rewrite"> inside your applicationHost.config file.
If you are on a shared hosting environment and you see that this feature is not working, ask your provider if they have given you the permission of configuring this part.
Source: http://www.tugberkugurlu.com/archive/remove-trailing-slash-from-the-urls-of-your-asp-net-web-site-with-iis-7-url-rewrite-module
I know this is an old post, but Mihai's answer can make your application vulnerable to open redirects attack (see this)
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
This redirect URL can be used for an external redirect, so make sure you have other validations in place before this rule is evaluated or change the redirect to make it internal instead. If you really want to remove the trailing slash and keep it internal, you can change it to:
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
Cheers

HTTP Error 404.4 - Not Found The resource you are looking for does not have a handler associated with it

I've hosted a site in IIS but whenever I browse to the site I get 404.4. How can I solve this? I've referred several posts and they all say the issue is about staticfile but it is already mapped. What more can I do? Here is the attached picture of handler mappings in my iis 7.0
Any ideas?
EDIT:
I have this url rewriter set up:
<rules>
<rule name="Imported Rule 1-1" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{SERVER_PORT}" pattern="80" />
</conditions>
<action type="Rewrite" url="https://abc.com/{R:1}" />
</rule>
When I disable this rule the http:// request is correctly handled. But when I enable it, I get this error.
Yet another update:
If I replace this:
<action type="Rewrite" url="https://abc.com/{R:1}" />
with
<action type="Redirect" url="https://abc.com/{R:1}" />
It all works out pretty well.
I was having the exact same issue. I installed Application Request Routing component and then set the Proxy enabled and selected the Use URL Rewrite to inspect incoming requests entered the redirect url alias and mine worked

Resources