I'm trying to modify an URL with a URLrewrite mediator but it seems to has no effect.
I want to replace the word "user1" to "customer1", and then send the request to an endpoint
In my proxy i recieve this URL:
"/services/myproxy/user1"
And i have to rewrite it to:
"/services/myproxy/customer1" (and then to endpont: "http://endpoint.com/customer1").
The URLRewrite mediator is:
<rewrite xmlns="http://ws.apache.org/ns/synapse">
<rewriterule>
<action value="customer1" regex="user1" type="replace" fragment="path"/>
</rewriterule>
</rewrite>
but at the end the proxy sends the URL request with "user1" instead of "customer1"!!
whats wrong in my config?? I don't see any errors in my log!!
thanks!!!
Following syntax is working perfect for me. What is the version of ESB you are working?
<rewrite>
<rewriterule>
<action value="customer1" regex="user1" type="replace" fragment="path"/>
</rewriterule>
</rewrite>
<send/>
I had the similar problem. In my case, I missed to set the outProperty back into REST_URL_POSTFIX after rewriting the url. Hope this can help someone having same problem in the future.
<sequence>
<property name="REST_URL_POSTFIX" expression="get-property('axis2','REST_URL_POSTFIX')"/>
<rewrite inProperty="REST_URL_POSTFIX" outProperty="REST_URL_POSTFIX">
<rewriterule>
<action fragment="path" type="replace" regex="^/soap/sms" value="/sms" />
</rewriterule>
</rewrite>
<property name="REST_URL_POSTFIX" scope="axis2" expression="get-property('REST_URL_POSTFIX')"/>
^^ Make sure to set this back ^^
</sequence>
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>
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
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.
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>