web.config 301s for all files but one - iis

I'm trying to set up 301s for a site which will bounce all old pages to the homepage (it was a large site that is now a single page).
The server's Windows based, however, so no htaccess fun for me.
Could anybody assist with producing a web.config file that redirects everything to the homepage via 301s?

This may work:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="301 Redirect Everything To Home" stopProcessing="true">
<match url=".+" />
<action type="Redirect" url="/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
But is will redirect everything, including images, include files etc.
Could you explain your motive for this as generally it's a bad move. It causes a poor user experience, robots don't like it, and nothing knows if a page is really missing or not.

I suggest you to try "IsapiRewrite" 3rd party module/DLL
ISAPI_Rewrite is a powerful regular-expressions-based URL rewriter for
IIS. It is compatible with Apache mod_rewrite making it possible to
move configurations from Apache to IIS and vice versa just by copying
.htaccess files (please see this compatibility chart). It is used for
search engine optimization, to proxy another server's content, stop
hotlinking or strengthen server security.

Related

IIS URL Rewriting - Change a querystring key and value into a route

I've recently implemented IIS URL Rewriting on one of my websites. I'm using URL Redirection rather than rewriting for everything. All of my static redirections are working perfectly, however, there's one specific type of dynamic redirection that I can't seem to make work.
I had old URL's that looked like this:
http://example.com/?tag=mytag
I'd like this to be redirected to the new URL format of:
http://example.com/tag/mytag
For these URL's the querystring key (tag) is known and fixed, however, the querystring value ("mytag" in the example above) is entirely dynamic and unknown in advance (so I don't believe it's therefore possible to use IIS Rewrite Maps).
Is is possible to add an IIS Rewrite rule that performs this kind of redirection for all possible querystring values that may be supplied?
Yes, the guts of the solution are below. Whats going on is...
1st condition means only apply this rule to the top level of the site. So http://example.com/?tag=mytag will redirect, whereas http://example.com/foobar/?tag=mytag wouldnt.
2nd condition is the magic. It only runs if a query param called tag exists, and the (.*) is a regex to grab the value for use in the new URL.
The action uses the value you grabbed in the 2nd condition referenced as {C:1}. appendQueryString does exactly what it says - set as appropriate. redirectType should be left as Temporary (HTTP response code 307) until your happy, then change it to Permanent (HTTP response code 301). Once you send a 301 response the client(/search engine) will potentially cache the response and not re-request from the server causing problems if you make a mistake.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect based on tag query value">
<conditions>
<add input="{REQUEST_URI}" pattern="$" />
<add input="{QUERY_STRING}" pattern="tag=(.*)" />
</conditions>
<action type="Redirect" url="tag/{C:1}/" appendQueryString="false" redirectType="Temporary" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

web.config & Aruba - URL Rewrite

I'm developing my first website and just learnt about the web.config file for IIS, so what I'm trying to do is to hide different parts of the url.
For example the homepage is www.domain.com/it/homepage.html and I'd love to make it appear as www.domain.com/it/homepage
I haven't found anything about removing an .html extension on the net, just a lot of .aspx which I tryed to replace with .html, failing miserably.
Another side question: is it possible to redirect errors with web.config ? I've seen a lot of .htaccess based solutions but that's it.
EDIT: Forgot to say that the website is hosted by ARUBA, on their windows oriented server
You are trying to change the URL of your site, which is the way to access it... that's a pretty odd action to do. When you get a request to your server for a certain page, the URL is parsed as the path to that file. If you want to change the URL, you need to change the name of the file - and if you wouldn't like having a .html in the end, then perhaps the file shouldn't be a html file - however, your goal is different. You want to have no extension at all.
Luckily, there is a way to have a url endpoint which doesn't have any file extension is all. That would be a folder. Folders dont have an extension to them, however they have no content by themselvs except the file they're linking.
Side note: There's another way, which is the one you'd usually see around the web. PHP could have other things in the URL than just the endpoint, but you asked about windows based HTML/ASPX windows backed pages.
So - yeah, the only way I see to have no extension at all is letting the user navigate through folders. The only question left is, why would you want this anyway?
You can use the following configuration in your web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="niceURL" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

IIS Throwing HTTP 500 for rewrite rules

When I put my web.config into any folder/main directory it seems to be throwing the HTTP error code: 500--unfortuenly I don't have access to the logs so I can't see why, so surely it's down to my web.config - I've never used IIS before but I'm trying to re-route all requests to a file called 'api.php', here's my web.config file.
<rewrite>
<rules>
<rule name="rule 1Q">
<match url="^/.*" />
<action type="Rewrite" url="/api.php" />
</rule>
</rules>
</rewrite>
Apache equivalent:
RewriteEngine on
RewriteRule ^/.* /api.php
Any help is greatly appreciated.
This is not an exact answer because I am not sure of your server variables but here is something that might be useful to you. Here. This walks through the IIS set up for version 7 and it has some basic concepts. There is rewrite module/tool that could help but I haven't used it. And another document here...Shows the GUI interface like the first link and is in 7.5.
Again not specific solutions but hopeful you have some server gurus there that can help you at least get the IIS settings right (or at least not sound dumb if you have to communicate something specific to them) if this is a first time IIS Isapi venture for you.

IIS - Mapping one extension to another

I did a bit of search but can't find a complete answer to my question:
I wonder if it's possible to set my IIS 7.5 to map one "custom" extension to another "physical" extension.
Eg.
I have Default.aspx, I'd like my server to serve this file to a request of Default.foo.
The mapping questions/answers I found are all about having Default.foo files, and mapping them to the proper handler; that's not my case, I just like to have a sort of masking of the real physical file extension.
Is it possible?
TY
The mapping should be setup between default.foo and default.aspx, mapping extensions cannot achieve this goal. You may use URL Rewrite module to create a rule to rewrite default.foo to default.aspx.
A simple example is as below,
<rewrite>
<rules>
<rule name="foo" stopProcessing="true">
<match url="(.*)\.foo" />
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
</rules>
</rewrite>

Problem with URL rewrite on IIS 7.5

I'm trying to use the URL Rewrite module for IIS 7.5 to redirect all HTTP requests to HTTPS for my ASP.NET website. The site works fine at the moment but forces the user to type the https:// in the address bar.
I followed the instructions in this article. Everything seems to be fine: I've tried putting the rule in the web.config and it shows up in the UI as it should; I've also done the reverse and can see the changes in the web.config when I use the UI to add the rule. I have RequireSSL unchecked for the site. Unfortunately I still just get a 404 when I try to hit the site via http://.
I've tried a few different action urls including {HTTP_HOST}/{R:1} and the one shown below.. nothing works.
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"
redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
I'm fairly new to this and pretty frustrated at this point. Seems like this should be a lot easier. Any advice would be appreciated, thanks..
Reposting from ServerFault as it's been sitting unanswered for a while.
HTTP Error 404. The requested resource is not found
Do you actually have binding for HTTP 80 port? Sounds like you do not have it (only HTTPS).
The reason I'm asking is the quoted text is the exact message that I would see if I request unknown to IIS domain (when there is no catch-all defined) or domain is not bound to the requested port.

Resources