Using web.config files to rewrite for my program - iis

I am looking for a way to use the URL Rewrite module to make the URLs for my program look cleaner.
I have been looking into IIS rewrite for a while now and whenever I get to the point where I think I understand it, nothing works.
I have this layout for my program.
etreecycle.co.uk/
- This has nothing to do with my program, this is a store for another project. (Wordpress)
etreecycle.co.uk/websites/MPW/
- My program is installed here.
etreecycle.co.uk/websites/MPW/index.php
- I want the first section of the domain to be put here, for example.
etreecycle.co.uk/websites/MPW/index.php?page=posts&action=1234
- I want this url to look like this:
etreecycle.co.uk/websites/MPW/post/1234
I also have an index.php in the directory etreecycle.co.uk/websites/MPW/admin/
This should take the same layout.
For example;
etreecycle.co.uk/websites/MPW/admin/?page=settings&action=save
- should look like;
etreecycle.co.uk/websites/MPW/admin/settings/save
Can anyone help me achieve this with IIS URL Rewrite? Thank you.

Here's an example:
<rewrite>
<rules>
<rule name="home" stopProcessing="true">
<match url="^settings/(\S+)$" />
<action type="Rewrite" url="admin/?page=settings&action={R:1}" />
</rule>
</rules>
</rewrite>

Related

How to rewrite one image with another in IIS using URLRewrite

Here is my problem, I need to rewrite one image with another (don't ask why).
Simple URLRewrite rule is not working.
Every time someone fetch this URL: http://example.com/images/001.jpg
IIS should show 002.jpg (http://example.com/images/002.jpg)
web.config:
<rules>
<rule name="img1" stopProcessing="true">
<match url="images/001.jpg" />
<action type="Rewrite" url="images/002.jpg" appendQueryString="false" />
</rule>
</rules>
I tested your URL rewrite rule and it works normally on my side.
So please try to clear your browser’s cache and try again.
And do you get any errors? If not, you can only use FRT to view detailed messages.

IIS UrlRewrite for reverse proxy only working if folder exists on primary website

I've got two websites on the same box and I want to reverse proxy a folder on one to the other. It is only working for directories if I create the directory on the parent website.
so i want http://site/odata/Books
to go to
http://myodatasite/odata/Books
Pretty straightforward, but it is not working unless I go to wwwroot/site and create the /odata/Books folders there. If I do this, the rewrite works. If I call /odata/Authors, again it will 404 unless I create an Authors folder.
It seems like I need to have a wilcard mapping in place in IIS or something else is causing the rewrite to fail. I have tried adding a wildcard mapping pointing to aspnet_isapi and had no changes, possibly because of integrated mode but I haven't found anything that is helpful online yet for this.
Does anyone know why my rewrite is not working for directories but a redirect works fine?
<rewrite>
<rules>
<!-- Does Not Work unless folders exist on current site! -->
<rule name="OdataRoutes" stopProcessing="true">
<match url="^odata/(.*)" />
<action type="Rewrite" url="http://myodatasite/odata/{R:1}" />
</rule>
<!-- Works -->
<rule name="OdataRoutes2" stopProcessing="true">
<match url="odata2/(.*)" />
<action type="Redirect" url="http://myodatasite/odata/{R:1}" />
</rule>
<!-- Works -->
<rule name="OdataRoutes3" stopProcessing="true">
<match url="(.*)\.odata" />
<action type="Rewrite" url="http://myodatasite/odata/{R:1}" />
</rule>
</rewrite>
Looks like it wasn't the mappings at all. Turning on Failed request tracing and monitoring the successful request and the failed request, it seemed the directory rewrite was being passed from ARR to the MvcHandler. Not sure why the redirect wasnt and the rewrite was, but after seeing that, the fix was pretty easy.
routes.IgnoreRoute("odata/{*pathInfo}");

How to redirect URL's in IIS

I have a website setup in IIS, current working URL is http://hr.something.com/ess
I need to have a redirect, so that if the users type in http://hr.something.com they will still end up at the /ess page.
Currently just typing in http://hr.something.com gives the default IIS landing page.
Everything i've found online talks about adding/removing trailing slashes or doing rewrites (which i dont think is what is needed here)
Apologies if there are already answers for this, but im sure im using the wrong terminologies, leading me to the wrong answers.
you should install the iis rewrite module
and see the
https://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
create the rediretly rule and you could test in iis manager
<rewrite>
<rules>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="article.aspx?id={R:1}&title={R:2}" />
</rule>
</rules>
</rewrite>

What's the proper method to tweak the URL in IIS or in web.config?

I am using Sitefinity CMS, one of my website sections for my pages is showing up in the URL and it makes the URLs look not very friendly, the section name is 'Footer' and the URL looks like this:
http://www.domain.com/footer/press-releases/first-press-release
How do I change/rewrite this URL in IIS or in web.config and remove the 'footer/' only so the URL looks like:
http://www.domain.com/press-releases/first-press-release
Thank you
In Sitefinity 6.3 and above you can edit the URL structure:
http://www.sitefinity.com/developer-network/forums/general-discussions-/sitefinity-6-3-released
This means, that even if the page is under the Footer group page, then you can remove the /footer/ from the URL of the page.
Just edit the Title and Properties and click on Change next to the URL.
I'd like to suggest you take a look at the IIS module URL Rewrite
http://www.iis.net/downloads/microsoft/url-rewrite
It would allow you to add rules allowing the 301 redirect you appear to need.
With the module installed you could add this to your web.config file:
<rewrite>
<rules>
<rule name="PressRelease" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^first-press-release$" />
<conditions>
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/press-releases/first-press-release" appendQueryString="false" />
</rule>
</rewrite>

IIS ReWrite Rule for removing url segment

I am trying to redirect requests to my site from:
pbt.mysite.com/pbt/index.php?querystring....blahblahblah..
so I'd like to remove the /pbt/ segment of the url and keep the remaining query
to:
pbt.mysite.com/index.php?querystring....blahblahblah..
I've setup an IIS Rewrite rule with the following:
<rewrite>
<rules>
<rule name="Rewrite remove PBT segment from URL">
<match url="^/pbt/([/_0-9a-z-]+)"/>
<action type="Rewrite" url="{R:1}"/>
</rule>
</rules>
</rewrite>
But this doesn't seem to work..
I'm wondering if there is a confusion in my rule because the subdomain is the same as the segment I want to remove (but keep the subdomain)
Additionally, this is a drupal site hosted in IIS so there may be a better way to do this in php (which I know nothing about)
Any ideas?
You have a leading slash that needs to be removed. Also, if you want to match on files and folders (not just folders as in your example), change the part between the parens too like so:
<match url="^pbt/(.*)$"/>

Resources