I am a real noob in IIS URL rewrite module.
I want to rewrite all requests of
127.0.0.1/Content/[anything may come here]
to
127.0.0.1:7078/Content/[anything may come here]
I am very bad in regular expressions and I do not know how to do this
I tried using the wildcard feature in URL Rewrite module and did this:
Requested URL matches the pattern using wildcards
127.0.0.1/Scripts/*
then rewrite to
127.0.0.1:7078/Scripts/*
(Action Type is Rewrite)
I am attached a screenshot. I am not sure I am doing this the right way, because it is not working.
1/ You don't need the host part in the Match URL Pattern : /Scripts/* should work.
2/ If you want to match the wildcard in the Match URL Pattern to the Rewrite URL, you'll have to use something like {R:0} in the Rewrite URL. For example 127.0.0.1:7078/Scripts/{R:0}.
3/ I'm not sure you can rewrite to a different port. If rewrites does not work, try Redirect as Action Type instead.
If you want to hide port 7078, you might need to use Application Request Routing (Reverse Proxy).
Sources : http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module & http://forums.iis.net/t/1165389.aspx?URL+Rewrite+to+specific+port
Related
Is it possible to rewrite/redirect a url such as this:
http://example.com?id=123&id=123
To instead be:
http://example.com?id=123
The actual reason for doing this is a bug in code, but a URL rewrite/redirect would be a quick workaround.
Didn't realize it was possible to add a condition for {QUERY_STRING} that matches the pattern id=(.*)&id=.* and then just redirect to http://{HTTP_HOST}/{R:0}?id={C:1}
I'm using Ocpsoft Rewrite, to perform URL rewriting in a JSF project. I have a redirect rule, which works fine:
.addRule()
.when(Direction.isInbound().and(Path.matches("/venue/{id}")))
.perform(Redirect.temporary(context.getContextPath() +
"/protected/index.xhtml?venueID={id}"));
However, because of the redirect, this changes the URL in the navigation bar. I thought I could use a Join rule instead, but it doesn't work as i expected:
.addRule(Join.path("/venue/{venueID}").to("/protected/index.xhtml"))
.perform(Log.message(Level.INFO, "Rewrite is active!"));
I thought this rule would redirect from, for example, foo/venue/123 to foo/protected/index.xhtml?venueID=123, but I don't get the ?venueID=... parameter appended to the URL.
Anyone knows what the correct rule should look like?
Your rule looks correct. But a Join doesn't result in a redirect. Instead it forwards the request internally. This means that the URL isn't changed. So you won't "see" the parameter venueID in the URL. But you will be able to read the parameter using the standard Servlet API:
String id = HttpServletRequest.getParameter("venueID");
If you really want, you can do a Forward instead:
.addRule()
.when(Direction.isInbound().and(Path.matches("/venue/{id}")))
.perform(Forward.to("/protected/index.xhtml?venueID={id}"));
But this won't handle outbound HTML link correction like Join will!
I am looking and looking and coming up with all different patterns, but no such luck. I require a rewrite rule to handle the a replacement of a string xyzlisting with xyz-listing. It may be anywhere in the url. Is there a straightforward way to write this rule?
I am not so experienced with IIS. However, I can suggest something:
In Apache mod_rewrite, you can use this rule:
RewriteRule (.*)(/\w+)(listing)(.*)$ $1$2-$3$4
This rule will split whatever string in the format anything followed by 'listing' that comes after mydomain.com/ with a '-'. Which results in 'anything-listing', wherever in the URL.
This will only change the last occurrence of this type of string. It will not replace more than one occurrence.
You can import this URl rewrite rule from Apache to IIS using this IIS extension:
IIS Extenson page for url rewrite module
Hope this helps :)
I have set up an inbound rule in the IIS URL Rewrite module, but it is not working.
Here's my setup.
What I want is to say that if the user's browser navigates to a.b.com (the first rubbed out part - oh and of course it's not literally "a.b.com" but something else of that form) then he should be redirected to http://www.d.com/foo (the second rubbed out part).
I've used the the Test Pattern feature and it does match correctly.
You may have to set a condition to make it work.
Is it a wildcard, exact match, or regex pattern? That will also determine which things you will need to make it work
In your case you can just use the wildcard matching and it should work.
I'm new to using the URL Rewrite module and I'm having trouble with what I thought would be a simple URL rewrite for forum threads (using IIS 7.5)
I need to rewrite:
/forum/100/2534/friendly-title
or:
/forum/100/2534/334/comment/friendly-thread-title
to:
/forum/?forum=100&thread=2534&post=334&postType=comment
The rule that I have written (not working) is:
^forum/([1-9][0-9][0-9]*)/([1-9]*)/(([1-9]*)/(post|comment)/)?([a-zA-Z0-9-]{5,50})$
Which maps to:
/forum/?forum={R:1}&thread={R:2}&post={R:4}&postType={R:5}
I'm getting a 404 error.
It's correct that {R:4} and {R:5} are empty when you use the first URL. That's because there are no values for these fields. The RegEx still matches though so the URL will still be rewritten. Your code should properly handle empty values for the post and postType querystring parameters to display the entire thread and not just a specific comment (at least that what I assume is suppose to happen).
By the way, a more logical URL structure would be:
/forum/100/2534/friendly-thread-title/comment/334
This won't help you this this particular problem though but just on a side note.