The following url-rewirte rule is not working,
<rule>
<from>^/coupon.do\?cc=([A-Z]{4})$</from>
<to last="true">/services/1.0/coupon/$1</to>
</rule>
redirect from /coupon.do?cc=ABCD to /services/1.0/coupon/ABCD is not working.
Please let me know my mistake.
Default type for <to> is forward, that said for redirect you have to change it explicitly to have type="redirect".
However, to have URL matched to your pattern, you need to add use-query-string="true" to your <urlrewrite> opening tag. So this should work,
<urlrewrite use-query-string="true">
<rule match-type="regex">
<from>^/coupon.do\?cc=([A-Z]{4})$</from>
<to type="redirect" last="true">/services/1.0/coupon/$1</to>
</rule>
</urlrewrite>
And don't forget to have match-type="regexp" for your rule.
Related
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.
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>
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>
I have the following redirect in place:
<rule>
<condition name="host" operator="equal">^(www.)?test.redirect.com$</condition>
<from>^?</from>
<to type="redirect" last="true" encode="true">http://www.redirect.com/test/test-123</to>
</rule>
It does redirect, however it redirects to http://www.redirect.com/test/test-123http://www.redirect.com/test/test-123. Does anyone know why it is outputting twice like that?
As a side note I want to add that it is NOT being redirected twice.
The <from> clause was incorrect:
<rule>
<condition name="host" operator="equal">^(www.)?test.redirect.com$</condition>
<from>^(.*)</from>
<to type="redirect" last="true" encode="true">http://www.redirect.com/test/test-123</to>
</rule>
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