Mask URL to subdomain using IIS - iis

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.

Related

IIS dynamic URL rewrite

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

301 redirects specific pages with get parameters and non-specified pages

I have my old website old.com and my new website new.com. I want to create 301 redirects in the .htaccess for some specific pages and some generic 301 redirects as well.
Get parameter redirects:
old.com/a/test?u=blah redirect to new.com/a/test?u=blah
old.com/a/test redirect to new.com/a/test
old.com/a/test.php?u=blah redirect to new.com/a/test?u=blah
As you can see the only thing that changed was the domain name. How can I redirect users to the new domain but also keep their get parameter the same. So regardless of what u=, it forwards the u= parameter to the new URL. Of course if there is no u=, it still redirects to the page (as per second example)
Get parameter without putting get parameter
old.com/a/foo?u=blah redirect to new.com/a/foo
old.com/a/foo redirect to new.com/a/foo
old.com/a/foo.php?u=blah redirect to new.com/a/foo
As you can see, it directs to the new domain but does not carry the u= parameter. Same applies for the second example.
Redirect Directory
old.com/blog redirect to new.com/blog
old.com/blog/23452/how-to-tie-a-tie redirect to new.com/blog
If the site is in the blog directory, regardless of what comes after the blog directory in the URL, it always redirects back to new.com/blog
I am unsure on how to do these types of specific redirects. I only understand how to direct a specific URL like so Redirect 301 old.com https://new.com

Redirect any URL to new domain regardless of protocol, third-, second-, or toplevel domain

I would like to redirect a variety of old domains to a new domain. The challenge is that the rewriting should occur regardless of:
Protocol (http or https)
subdomain (with www. or without www.)
second-level-domain (e.g. domainA, domainB, or domainXYZ) since the list of old domains on this server is rather long
top-level-domain (e.g. .com, .fr, .de)
The new output-URL should always be: https://www.newdomain.com/oldpath
Any path or filename in the old URL should be added to the new URL
I´ve tried a variety of rewriting conditions and rules but so far none has achieved the desired result. Any help would be highly appreciated.
Instead of mod_rewrite, you might try Redirect, which seems appropriate for your requirements
Then any request beginning with URL-path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-path will be appended to the target URL.
Redirect / https://www.newdomain.com/
When it works as expected, you may set the status code to 301 (permanent redirect).

Difference between IIS Redirect and Rewrite (in relation to redirecting)

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)

Using .htaccess Redirect 301 without changing URL in Address Bar

I currently have a WordPress Multi-Site Network set up. The main website is located at "http://safesideinc.com." Then, there is another sub-domain "http://danielgosek.safesideinc.com."
I want the URL "http://safesideinc.com" to lead to "http://safesideinc.com," and the URL "http://danielgosek.com" to lead to "http://danielgosek.safesideinc.com."
Using a 301 Redirect in .htaccess, I can achieve this. However, I would like it so that entering "http://danielgosek.com" in the URL bar leads to "http://danielgosek.safesideinc.com." WITHOUT CHANGING the URL displayed--in this case, the displayed URL should remain "http://danielgosek.com."
Are there any rules that could help me achieve this?
Not possible, a 301 - Permanent Redirect, is an instruction to the BROWSER that the resource has moved permanently and the BROWSER should re-direct to the provided new URL.
If you don't want the URL to change you either need a Reverse proxy set-up between the two virtual hosts / domains, or if danielgosek.com is just an alias, same IP and served from the same Apache virtual host, you could use an internal rewrite.

Resources