Cross-domain URL Rewrite possible? (Entire URL) - url

Say I have a domain name bound to my site. The domain name is www.example.com
Normally, it will be easy to rewrite the URL from www.example.com/foo to www.example.com/bar.
However, I would like to rewrite www.example.com into www.foobar.com, is this rewrite possible?
Notice I'm talking about "Rewrite" not "Redirect". Using redirect, the URL will be translated into www.foobar.com after page loads. In my case, I would like it to go to www.foorbar.com but still have www.example.com as the web URL in the address bar for the browser.
I'm probably asking too much, yet I really don't know how far we could go in techniques these days.
By the way I'm using IIS 7

Rewrite? No. You can set multiple domain names to go to the same place, but this would be with your domain host, not an IIS setting. If you could arbitrarily rewrite URLs, think of all the security problems that would arise.

Yes if foobar.com is also a website you own in your network. It's the reverse proxy feature of URL rewrite:
http://weblogs.asp.net/owscott/archive/2013/10/24/creating-a-reverse-proxy-with-url-rewrite-for-iis.aspx

Related

URL masking via VHOST or htaccess

I would like to fake mask URL to another url..
Example:
I have domain www.domain.tld..
And I want to mask it to www.google.com
So, if someone type www.domain.tld/something, it will load URL www.google.com/something - without redirect!
Is it possible? Both domains are mine.
I can use VHOSTS, or htaccess..
If both your domains are served by the same server, you can use an internal URL rewrite to do this. Apache would internally server the content from domain B when a request comes in for domain A. The mod_rewrite documentation has all the information. It's very powerful, so there are many options.

Let sub.mydomain.com point to myotherdomain/MyApp (DNS)

This is what I would like to achieve, but I am a bit of a DNS noob:
1) I have a webapp running on a VPS at myfirstdomain.com/MyApp
2) I want this: going to myapp.myOTHERdomain.com should be heading to myfirstdomain.com/myApp without redirecting using a php script or doing some CURL business. So the url in the addressbar of the browser should stay the same.
Is this possible by doing something with DNS (or some different solution)? I own both domains.
Within DNS, it is not possible to redirect to a subdirectory, but what you can do is create a CNAME record like this:
myapp.myOTHERdomain.com. IN CNAME myfirstdomain.com
That way myapp.myOTHERdomain.com will point to the A record for myfirstdomain.com.
You may configure your webserver to do the HTTP redirect.

How to have a domain redirect to a subdirectory?

Using only DNS, how can I have http://www.example.com/ either redirect or resolve to http://www.anotherdomain.com/example ?
UPDATE:
Since it's been mentioned below that DNS cannot be used, what's the next best alternative (minimize load on server and provides the fastest redirect experience for the user) ?
You can't. DNS doesn't handle URLs, just maps names to IPs.
URLs aren't part of DNS, only domain names are.
Just as Tim Howland said, you can't. You need to use something like the URL rewrite module for Apache or a redirect page (both on example.com).

DNS File Mapping

I'm trying to work out a feature for a Web application, but I'm a bit confused at this point. I was wondering if anyone can shed some light on the following scenario.
Say, my Web app is located at domain1.com and a users website is located at domain2.com. What I would like to allow is for the user to be able to map their domain to one of the files/pages on my server. So if someone accesses domain2.com/files then it will internally and transparently route to domain1.com/files.aspx?domain=2 (notice the domain parameter).
I know this can be done with a simple file redirection (301 or 302) on the users server, but I would like to achieve this on the DNS level. How can I go about it?
Thanks in advance!
You can map domain2.com (or a subdomain) to the same IP domain1.com runs on using the A record. That's about everything you can achieve on DNS level, as it doesn't care about directory structures.
Simply put, you can't. If you wanted to point foo.domain1.com to the record for foo.domain2.com, then you can probably use a CNAME record but DNS has no clue about HTTP URLs.
The "HTTP Redirector" plug-in for Simple DNS Plus does just that if you configure it to redirect to "http://domain1.com/files.aspx?domain=#HOST#"
Technically it actually does a HTTP redirect (native DNS is not possible), but it is done at the DNS servers instead of the web-server.
See http://www.simpledns.com/kb.aspx?kbid=1258

How do you see the client-side URL in ColdFusion?

Let's say, on a ColdFusion site, that the user has navigated to
http://www.example.com/sub1/
The server-side code typically used to tell you what URL the user is at, looks like:
http://#cgi.server_name##cgi.script_name#?#cgi.query_string#
however, "cgi.script_name" automatically includes the default cfm file for that folder- eg, that code, when parsed and expanded, is going to show us "http://www.example.com/sub1/index.cfm"
So, whether the user is visiting sub1/index.cfm or sub1/, the "cgi.script_name" var is going to include that "index.cfm".
The question is, how does one figure out which URL the user actually visited? This question is mostly for SEO-purposes- It's often preferable to 301 redirect "/index.cfm" to "/" to make sure there's only one URL for any piece of content- Since this is mostly for the benefit of spiders, javascript isn't an appropriate solution in this case. Also, assume one does not have access to isapi_rewrite or mod_rewrite- The question is how to achieve this within ColdFusion, specifically.
I suppose this won't be possible.
If the client requests "GET /", it will be translated by the web server to "GET /{whatever-default-file-exists-fist}" before ColdFusion even gets invoked. (This is necessary for the web server to know that ColdFusion has to be invoked in the first place!)
From ColdFusion's (or any application server's) perspective, the client requested "GET /index.cfm", and that's what you see in #CGI#.
As you've pointed out yourself, it would be possible to make a distinction by using a URL-rewriting tool. Since you specifically excluded that path, I can only say that you're out of luck here.
Not sure that it is possible using CF only, but you can make the trick using webserver's URL rewriting -- if you're using them, of course.
For Apache it can look this way. Say, we're using following mod_rewrite rule:
RewriteRule ^page/([0-9]+)/?$
index.cfm?page=$1&noindex=yes [L]
Now when we're trying to access URL http://website.com/page/10/ CGI shows:
QUERY_STRING page=10&noindex=yes
See the idea? Think same thing is possible when using IIS.
Hope this helps.
I do not think this is possible in CF. From my understanding, the webserver (Apache, IIS, etc) determines what default page to show, and requests it from CF. Therefore, CF does not know what the actual called page is.
Sergii is right that you could use URL rewrting to do this. If that is not available to you, you could use the fact that a specific page is given precedence in the list of default pages.
Let's assume that default.htm is the first page in the list of default pages. Write a generic default.htm that automatically forwards to index.cfm (or whatever). If you can adjust the list of defaults, you can have CF do a 301 redirect. If not, you can do a meta-refresh, or JS redirect, or somesuch in an HTML file.
I think this is possible.
Using GetHttpRequestData you will have access to all the HTTP headers.
Then the GET header in that should tell you what file the browser is requesting.
Try
<cfdump var="#GetHttpRequestData()#">
to see exactly what you have available to use.
Note - I don't have Coldfusion to hand to verify this.
Edit: Having done some more research it appears that GetHttpRequestData doesn't include the GET header. So this method probably won't work.
I am sure there is a way however - try dumping the CGI scope and see what you have.
If you are able to install ISAPI_rewrite (Assuming you're on IIS) - http://www.helicontech.com/isapi_rewrite/
It will insert a variable x-rewrite-url into the GetHttpRequestData() result structure which will either have / or /index.cfm depending on which URL was visited.
Martin

Resources