URL Rewrite for subdomains in ASP.Net - asp.net

How can I make URL rewrite rule for this url:
example.com/account/login.aspx
to this url:
me.example.com/login
So any request to the folder /account will rewrite to me.example.com. Also sub folders and file like /account/subfoler/file1.aspx will rewrite to me.example.com/subfolder/file1
I already set the DNS wildcard to the app and all subdomains will take to the same ip address. All I need is the url rewrite rule.

You can achive this in IIS 7.0 Url Rewrite
OR
Write your own handler to intercept incoming request
To achieve this you can implement the IHttpHandler and process the url redirection logic in t he ProcessRequest method
Here is a very good example http://www.codeproject.com/Articles/30907/The-Two-Interceptors-HttpModule-and-HttpHandlers

Related

How to redirect with nginx but keep the old url

I have mainsite.com and a subdomain sub.mainsite.com.
The sub.mainsite.com has a cname record point to another online content web
Right now I will to redirect mainsite.com/sub to display the sub.mainsite.com content, but still keep the mainsite.com/sub URL.
How can I do that with Nginx?
You cannot do that. You can either redirect using return or rewrite directive. Either way, the URL is redirected. The difference is you can reframe the URL as required using rewrite directive.

Tomcat app http to https redirect displays ROOT in URL

Context path is set to ROOT in tomcat app because I want to access the URL without any path ex: https://URL/. AWS Loadbalancer just redirects to the app servers. It works if I directly access https site. But if I access http site, the http to https redirect takes to https://URL/ROOT and displays "page not found", then I'd to remove the ROOT to access the page. If any path is set in the context i.e https://URL/PATH/, the redirection works good but only if ROOT, http redirection is having this issue. I guess context.xml, web.xml, server.xml looks good to me. Obviously needs some tweak. Any help is appreciated please.
http listener rules had ROOT instead of default {path} hence why redirection happened. Right now it is fixed and I don't see ROOT in the http URL redirecting to https.

IHttpHandler to redirect "https://example.com" to "https://www.example.com"?

I use IIS7's HTTP Redirect feature to redirect http://example.com requests to http://www.example.com but this feature cannot be used in this way with https protocol.
Is it possible to use IHttpHandler to accomplish this?
If you use IIS7, you might want to try URL Rewrite Module.
https://web.archive.org/web/20211020203216/https://www.4guysfromrolla.com/articles/072810-1.aspx
http://www.jppinto.com/2010/03/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0/

Serve specific page according to domain name

We have a clients domain name (d1) pointing at one of our sites (s1) which is a .NET 4 web forms site.
The client has set up a subdomain on a different domain (d2) and pointed this at the s1 IP address.
We need to serve a specific page on s1 if the d2 domain is used and not have the page in the URL.
I would like to achieve this without a redirect if possible.
eg
example.com -> the site
x.example.net -> the site /thepage.aspx (but want the URL in the address bar to remain x.example.net, not x.example.net/thepage.aspx).
I've tried doing a Server.Transfer in begin request and while this worked, the postback didn't (I assume because it's because of the transfer but I don't know how to detect a postback in begin request and thus not transfer).
I thought there may be a way to leverage routing but there would be no path (just the domain name) so any route set up like this would presumably route all requests to this page if they don't get caught be a previous route - not ideal).
So, in short:
Is there a way to detect a postback in Application_BeginRequest in global.asax so I only transfer the inital request?
Or is there a way of mapping a domain name to a page without redirecting?
Is there some feature I don't know about that achieves this?
You can set up Rewrite Rules to do this. The following rule rewrites the root Url to /thepage.aspx only if the host matches x.example.net.
RewriteCond %{HTTP_HOST} (^x.example.net$)
RewriteRule ^$ / [NC,L]
If you have IIS7: you can do this using URL Rewrite.
If you have IIS6: you can set up ISAPI Rewrite on the server.
Depending on your setup, the 2nd line may include a slash:
RewriteRule ^/$ /thepage.aspx [NC,L]
You could write a HttpModule which examines incoming requests - if a request is for x.domain2.com, then you could invoke thepage.aspx like this:
Type page_type = BuildManager.GetCompiledType ("~/thepage.aspx");
Page page = (Page) Activator.CreateInstance (page_type);
page.ProcessRequest (Context);

Implement Rewrite Module to have ApplicationName with querystring

How can I rewrite the URL to have application name + querystring? For example I have a web application with the following querystring
mywebsite/default.aspx?UserName=xyz
How can I have URL with the folllowing
mywebsite?xyz
I have managed to implement RewriteModule using HttpApplication on Begin_request event and currently I can use this query
http://mywebsite/?xyz
Is there a way to have the url without /?
try,
rewrite ^/default\.aspx\?UserName=(.*)$ /?$1 last;

Resources