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.
Related
I'm having an issue when trying to configure redirections on IIS server. I have a website running in IIS and first of all i'd like to:
redirect all the incoming requests for that site from http->https
redirect all the incoming requests for that site if the URL is for example: https: //abc.org to https ://abc.org/loginpage
I set the first rule as explained here: https://www.ssl.com/how-to/redirect-http-to-https-with-windows-iis-10/
And then set the second rule as explained here: IIS 10 URL redirect from one domain to another
But it's still not working. Tried restarting IIS, restarting app pools, website, clearing browser cache...
Thanks!
You can try to use this URL Rewrite rule:
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" ignoreCase="false" />
</conditions>
<action type="Redirect" url="https://example.com/loginpage" redirectType="Found" />
</rule>
</rules>
</rewrite>
You need to modify example.com to abc.org.
we had an application (http://stellramapps.com/) which was running in server1, now the application has been migrated to server2.
We have done the DNS settings for the request coming to server1 to route to server2.
the IIS redirection rule also has been set with the regular expression = ^http://stellramapps to redirect to http://tdstest/
but still i face the below error
Can’t reach this page
•Make sure the web address http://stellramapps.com is correct
http:// is not included in HTTP_HOST so please try ^stellramapps$ instead of ^http://stellramapps.
Plesease ensure http://tdstest/ can be accessed from the server of stellramapps.
Then please install URL rewrite and ARR
https://www.iis.net/downloads/microsoft/application-request-routing
Finally, you can enable IIS manager->server node->application request routing cache->Server Proxy Settings->Enable Proxy and apply this rule
<rule name="redirect rule" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^stellramapps$" />
</conditions>
<action type="Redirect" url="http://tdstest/{R:0}" />
</rule>
I have an issue which is driving me mad.
I have a project which I set up and enabled SSL (By changing the SSL enabled flag to true in the application properties)
Then I changed the project url in the web properties to the SSL Url (Shown in the image above)
And finally, I added a rewrite rule to my web.config:
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
</rules>
</rewrite>
This was all fine. I was able to debug my application while on the new HTTPS url. The problem is now I have to test it back on HTTP, so I reversed my steps.
First I commented out the rewrite rule, then I changed the Project Url back to the normal http url and clicked "Create Virtual Directory".
And finally I changed the "SSL Enabled" to false.
This is where the problem lies. When I press F5, my browser uses the normal URL (The correct http one) but it redirects to a https url. I can't change it because when I do it just redirects.
It is driving me mad because there is no rule (that I can find) that is redirecting it. I even uncommented my rewrite rule and changed it to this:
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://{HTTP_HOST}{REQUEST_URI}" />
</rule>
</rules>
</rewrite>
To for it to use the http url, but it will not.
Can someone please help me?!?
In the end, this was pretty straight forward. I commented out the rewrite rule and then in the project properties, just set the override application root url to the http url while keeping the project url as the https version.
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 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