url-rewriting omitting directory from url? - url-rewriting

Is it possible to remove a directory from URL? for example for the below urls:
http://localhost:50656/umbraco/Surface/HealthInsurance/Application?Pid=26665&Lid=73&Spid=23
http://localhost:50656/umbraco/Surface/HealthInsurance/Results/73
there need to remove umbraco/Surface/ and make it
http://localhost:50656/HealthInsurance/Application?Pid=26665&Lid=73&Spid=23
http://localhost:50656/HealthInsurance/Results/73
Please guide what will be regular expression for this.

In the web server section of your web config you can add the following. It will match the url .*, which is everything and will map it to /umbraco/Surface/{R:0}. The R:0 is the entire captured response. Make sure you have the module installed. Here is a tutorial on how to check if you have your rewrite set and you can test it. http://www.iis.net/learn/extensions/url-rewrite-module/testing-rewrite-rule-patterns
<system.webServer>
<rewrite>
<globalRules>
<rule name="MapUmbarco">
<match url=".*" />
<action type="Rewrite" url="/umbraco/Surface/{R:0}" />
</rule>
</globalRules>
</rewrite>
</system.webServer>

Related

Change ORDS URL with IIS URL Rewrite

I've written a set of REST APIs (Oracle ORDS) with the URL following format:
https://servername:8443/ords/schema_alias/module_name/handler_name/p1/p2
The requirement from the client is that it be in the following format (will be used by an external tool):
https://servername:8443/handler_name/p1/p2
We are using IIS and I tried to achieve this with URL Rewrite:
Pattern: ^handler_name/([_0-9-]+)/([0-9]+)
Action type: Rewrite
Rewrite URL: ords/schema_alias/module_name/handler_name/{R:1}/{R:2}
The Test Pattern option in URL Rewrite worked as expected.
However when I test the URL I get a page not found (404). I am able to verify the configuration in the C:\inetpub\wwwwroot\site_name\Web.config file.
Can anyone please shed some light as to why the web server does not recognise the URL?
EDIT: additional information after #Deepak-MSFT 's Answer
Below is my rule's configuration:
And the detailed error message:
I have added the folder, but that did not make a difference:
C:\inetpub\wwwroot\b******MS
Below are the IIS sites:
I have tested below URL Rewrite rule is rewriting the URL from http://localhost:8443/handler_name/p1/p2 to http://localhost:8443/ords/schema_alias/module_name/handler_name/p1/p2
<rewrite>
<rules>
<rule name="Rule-1" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="localhost:8443" />
<add input="{REQUEST_URI}" pattern="/handler_name(.*)" />
</conditions>
<action type="Rewrite" url="ords/schema_alias/module_name/handler_name{C:1}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
Test Result
If you still get the 404 error then make sure the path in the file system is correct and folder exists.
Further, you could share the screenshot of the detailed 404 error. It could show the module name that is having issue. It could help you narrow down the issue.

URL rewrite from trailing string to GET variable

I've searched for this, but can't seem to come up with the right search terms to find - seems it would be a common question.
WIMP, IIS version is 8
I want to come up with a rewrite rule:
Incoming URL: http://example.com/1a2b3cdef
Rewritten to: http://example.com?p=1a2b3cdef
Note, the start of this url will always be "http://example.com/" (not the real domain name), that will never change.
From there my default document of index.php will retrieve the GET variable p.
Any help is greatly appreciated.
This is the configuration that can be applied in web.config.
<defaultDocument>
<files>
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="rewrite" enabled="true">
<match url="^[_0-9a-z]+" />
<action type="Rewrite" url="?p={R:0}" />
</rule>
</rules>
</rewrite>

web.config using an absolute path

I need to use a rewrite rule for a url(www.example.org/download.php) to hit another file called download.php, that is not in my root directory, but located in C:/repo/other_directory/test/download.php, however, it is not working. I have to use an absolute path in the rule. Any help on this would be greatly appreciated. My code is below:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule placestoswim" stopProcessing="true">
<match url="download.php" ignoreCase="false" />
<action type="Rewrite" url="C:/repo/other_directory/test/download.php" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I dont think this will work the url paramter of a rewrite is expecting a URL not a file system path.
If you cant move that location, can you create a virtual directory inside your existing site called downloads, and point its web root at your immovable folder C:/repo/other_directory/test/? Then in your web.config setup a rewrite to use this newly created path ~/downloads/download.php as the destination for your rewrite for ~/downloads.php

IIS Rewrite Rule for path

We need to redirect the URL below using IIS Rewrite module.
http://www.old.com.au/kids to http://www.new.com.au/somepath/kids
Could someone please help me?
Add this inside the rules node in web config for the site which is bound to www.old.com.au
<rule name="Redirect kids to new site" >
<match url="^kids$"/> <!-- only redirect kids and not something/kids or kids/something -->
<action type="Redirect" url="http://www.new.com.au/somepath/kids" />
</rule>

ASP.NET 4.0 Rewrite Rules in Global.aspx File Issues with rewrite

I have a rewrite rule I'm using in ASP.NET 4.0 on IIS7:
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite default to aspx" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="home.aspx" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<add value="home.aspx" />
</files>
</defaultDocument>
</system.webServer>
This rule takes: (http:/example.com/aboutus.aspx) and it removes the .aspx from the end of the URL. I'm running into problems with wordpress being installed on my subdomain (http:/www.example.com/blog) I get the following error due to my rewrite rule:
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /blog/.aspx
Does anyone know how I can fix the URL rewrite rule so it safely get to (http://www.example.com/blog/) and not add the .aspx at the end?
Is there some sort of syntax that can search for the blog subdirectory to ignore the directory '/blog/'?
Greatly appreciated! Thank you! :)
If you want your rule to be applied to every urls but the /blog/* ones, then you can use the negate option:
<rule name="Rewrite default to aspx" stopProcessing="true">
<match url="^blog/" ignoreCase="false" negate="true" />
<action type="Rewrite" url="home.aspx" />
</rule>
http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Rule_pattern_properties

Resources