I'm trying in Microsoft IIS 10 to do dynamic URL rewrite / redirect based on a condition that the URL contains specific info.
Match URL / Pattern: mysite/pages/viewpage.action?uniqueurl
Rewrite URL: mysite.xyz.xyz/pages/viewpage.action?uniqueurl
What I want to achieve is that whatever you write after mysite/pages/viewpage.action? it needs to rewrite to the same URL just with mysite.xyz.xyz added instead of only mysite.
Example 1:
mysite/pages/viewpage.action?thisisexample1 -> mysite.xyz.xyz/pages/viewpage.action?thisisexample1
Example 2: mysite/pages/viewpage.action?anothersite -> mysite.xyz.xyz/pages/viewpage.action?anothersite
When I'm trying to set up the above in the URL rewrite section i just end up at: https://mysite.xyz.xyz/pages/viewpage.action.
I have a generel HTTP redirect aswell to https://mysite.xyz.xyz when you come from mysite which works fine but I need to try and get specific URL rewrites to work aswell.
I found the solution.
It was to add HTTP redirect parameters to the HTTP redirect and change the Redirect Behaviour.
I added $S$Q to the HTTP redirect which fixed the issue in the regards to the question mark in the redirect which IIS couldn't handle without the extra parameters.
Besides that I need to change the Redirect Behaviour so I put a checkmark in 'Redirect all requests to exact destination (instead of relative to destination)
Edit: Typo
Related
I have an IIS webserver running a website. I've installed ARR3 to enable routing rules.
I'd like to redirect all the incoming request for the URL .mydomain/url2redirect/ to an Apache server installed on the same machine where is running SVN.
So in the inbound rule definition I've inserted the following:
Input: URL path after '/'
Pattern: *.mydomain/url2redirect/*
Action Type: Rewrite
Action URL: https://ip-address:8080/{R:2}
By testing the pattern, I get the desired result, and in the R:2 back reference I get the requested page I need to pass to SVN, but I get always a 404.
"url2redirect" doesn't exist but it should captured by the URL rewrite and forwarded to the Action URL.
I've added any outbound rule. Should I have to add something? what?
I've tried also to add a Reverse Proxy Rule, using the ARR template but, it's completely ignored, therefore I think that the routing is not working at all on IIS.
As far as I know, the url rewrite rule Pattern doesn't match the domain part.
That means mydomain will not include in the Pattern.
If you want to match the url2redirect, you should use below pattern.
url2redirect(.*)
Then I suggest you could modify your action url as below:
https://ip-address:8080{R:1}
Trying to 301 redirect traffic from:
www.domain.com/directory/
to
new.domain.com/directory/
It also needs to redirect:
www.domain.com/directory/dynamicallygeneratednames.html
to
new.domain.com/directory/dynamicallygeneratednames.html
I can make the first work easy enough but the second bit I just can't find the correct settings in the url rewrite or the http redirection modules in IIS. The full urls aren't actually files they are dynamically generated.
Any ideas?
You can do this using IIS URL Redirect Module and here is how to use it
then you will have to use some regex to separate parts of the original url
so lets consider www.domain.com/directory/whatever/comes/here/of/any/lengths
you can use this ^(/directory)(/.*)? regex pattern in iis redirect module to separate /directory and /whatever/comes/here/of/any/lengths into two chunks
{R:1} & {R:2} or {C:1} & {C:2} [depends how you use it]
then your final redirect should look like where you chose the new domain, /directory is matched and rest of the url gets transferred over
new.domain.com/{R:1}{R:2} or newdomain.com{C:1}{C:2}
The question may sound odd, but given an article, it is definitely possible to use the rewrite module to perform redirects just as with the redirect module. Both are able to issue a permanent redirect (301).
There is a question asking for the difference, but it talks about the rewrite module being used to purely rewrite not redirect. Another post makes this clear, but doesn't seem to get an adequate answer.
Hence, my question: What's the difference between these modules? Which is preferred over the other when it comes to redirects?
NOTE: THIS ANSWER DOES NOT answer difference between IIS Redirect (httpRedirect) vs URL Rewrite Module's Redirect but rather difference between URL Rewrite Module's (redirect vs rewrite).
If you are trying to hide complex URL (with querystrings) to more friendly URLs then Rewrite is the way to go as browser/Search Engines will always see 200OK and assume the content is coming from requested original URL.
If you are trying to indicate a change of resource to search engines/users of new URL then Redirect is the way to go as you are sending 301 status code saying that resource has moved from original to this new location.
IIS Redirect:
Redirecting happens at Client Side
Browser sees a different URL In address bar.
Client aware of a redirect URL.
301/302 can be issued. Edit: (303/307 can be issued too)
Good for SEO/Search Engine to indicate of new URL. mysite.com/abc to mysite.com/pqr
Can be redirected to same site or different site altogether.
IIS Rewrite:
Redirecting happens at Server Side
Browser does not see new URL in address bar.
Client unaware if content is served from a re-written URL.
No 301/302 are issued. This will have normal 200 OK assuming that rewritten URL Resource is available.
Good to hide unfriendly URL and also SEO. mysite.com/article/test-sub/ to mysite.com/article.aspx?id=test-sub
Generally for a resource within same site.
Request Handling (REDIRECT): www.mysite.com/abc to redirect to www.mysite.com/pqr
Client calls: www.mysite.com/abc
URL Rewrite Module sees a rule match for client URL and gives new redirect URL.
Server responds with 301 with new URL for client to call www.mystite.com/pqr
Client calls new URL www.mystite.com/pqr
Server responds with 200 OK for new URL. (address bar shows new URL)
Request Handling (REWRITE): www.mysite.com/abc which you want to point to www.mysite.com/pqr
Client calls: www.mysite.com/abc
URL Rewrite Module sees a rule match and provides new rewritten url to IIS i.e. www.mysite.com/pqr and Server makes request for that URL within IIS.
Server responds with 200 OK for original URL but with content from rewritten url. (address bar shows original URL and client does not know that you are serving content from different URL)
I am looking to mask or cloak a URL with a subdomain.
For example, if I have the URL http://example.com/news/article/this-is-an-article it would be possible to visit http://test.example.com/this-is-an-article and the same page would display. Notice: the desired secondary URL is a subdomain of the original URL.
I am using IIS 7. All of the examples I have looked at only change the structure for the existing URL (instead of mapping it to a sub-domain). I am looking for something different to a redirect (perhaps a rewrite, if that is the correct term).
Assuming you are using the IIS rewrite module, there are two main response types: Rewrite and Redirect.
A rewrite takes the existing url and changes it internally within the same site, so that a url that doesn't really exist on the site is remapped to an existing endpoint. The user does not notice the difference, the requested url returns the expected content. This only works within a site.
A redirect is used when you need to return content from a different site (such as in your case). Instead of rewriting the url internally, a 301 or 302 with a new url is returned to the browser. The browser than just requests that new url and gets the content from the second site. The user will notice a change of the url in the address bar.
So you have to use the redirect response type in the rewrite module, only in this case you can specify an absolute URL such as http://example.com/news/article/this-is-an-article
If both example.com and test.example.com are mapped to the same IIS site, you could use a rewrite rule.
After you've been able to successfully create a url rewrite how do you handle the original and other possibly ways to access a page. This of course to prevent duplicate content. For example if I have this:
RewriteEngine on
RewriteBase /
RewriteRule ^blog/(\d+)/([\w\-/\.]+)/?$ blog.php?id=$1&article_title=$2 [L]
I'm able to access the page by the url
https://www.mysite.com/blog/10/mysite.com (the mysite.com is the article title)
The problem is I'm also able to access the site by going to
https://www.mysite.com/blog.php?id=10article_title=sitetitle
https://www.mysite.com/blog.php?id=10
ect.
How are you supposed to handle those particular urls.
Also should I change the blog.php?id=10 to the rewritten url? Can I rely on something else and just start using the full rewritten url now? The site is new.
For my web site, I have the script that gets called from inside the rewrite detect the URI they were fetched from (using the "REQUEST_URI" variable that at least Apache sets), and redirect to the canonical one if they ever get called with the internal one (outputting a 301 direction).