URL masking/forwarding/redirecting - url

I have a website hosted on 000webhost and a paid domain was purchased from 1and1. 1and1 offers URL redirecting with HTTP or frame redirect, but I have opted to point the paid domain to 000webhosts name servers.
Currently this works to the point that when I type the paid domain in (www.paiddomain.co.uk), it points me to the correct website (www.freedomain.com). Once on this page any page that is clicked shows up in the address bar as www.freedomain.com/link when what I want is for it to show up as www.paiddomain.com/link.
What's the best way of doing this?

Terminology
origin server - the server that provides the original content
proxy server - the server that sits in the middle between the client and the origin server
In your case the origin server is freedomain.com. It sounds like you opted out of a proxy server and just have the DNS pointing to the origin server.
Reason
The first page loads fine because it is accessible by two domains. However the HTML content that was delivered has absolute links to the origin server. Therefor when the client clicks on it they are taken directly to the origin server.
Without a proxy server you have two choices
Get the origin server to generate absolute links to the domain you want.
Get the origin server to generate relative links.
This depends on how your pages are generated (static html, drupal, wordpress, custom app). But the net effect is that your links will be generated like this:
absolute URL
or like this:
relative URL
If your site uses cookies you will also need to figure generate them for the correct domain.
For systems that generate an absolute URL they will usually have a variable that stores the "site url", "base url", or similar either in their configuration or in the database.
With a proxy server
You can ask your proxy server to translate links (and cookies, etc) from freedomain.com to paiddomain.com. This depends on the proxy server, in apache you would use ProxyPassReverse.
1and1 is apparently not willing to be your proxy server:
http://faq.1and1.com/domains/domain_admin/domain_dest/3.html
They are willing to provide a frame (poor bookmarkability), or HTTP redirect (change the URL).

With a RedirectRule in the .htaccess file:
Example - Redirect from www.freedomain.com/link to www.paiddomain.com/link:
RewriteEngine On
RewriteCond %{HTTP_HOST} !www.freedomain.com/link$ [NC]
RewriteRule ^(.*)$ http://www.paiddomain.com/link/$1 [L,R=301]
More info

I was running in to this same problem when using the frame redirect offered by 1and1. My page had absolute URLs to an external site and when clicked they would load a blank page with my 1and1 domain in the title bar.
Chrome out put this error:
'absolute link to external site' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
Turns out when I clicked the links the browser was trying to open them in the frame 1and1 added to my page. The solution was to add the target attribute to my links and set it to _top. This causes the links to be opened fully in the current window/tab and ignore the frame.

Related

Microsoft Edge 400 error in textarea

When i write my website nonwww domain (domain.com) in Microsoft Edge i get an HTTP 400 error. The problem happend when i write this inside textarea "Search or enter new website". This is default in Edge and everybody writes in.
I dont understand what could be causing this problem? Every browser redirects normally.
Should i do some customization in htaccess file?
I found this solution but it seems not to work and i dont know if i am going in the right direction:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} Edge
RewriteRule .* http://www.example.com/? [NC,L]
Because of many reasons, partly as a legacy from a time when users are less internet-savy, most browsers will automatically adds www. (or .com) when:
You enter a domain without the protocol part (http://), and
The domain cannot be found.
It seems that Edge 11 doesn't do that.
If that is the case, your direction is correct.
But you must do it for and only for the virtual host that serve the non-www domain.
If your server does not know it should handle non-www domain, the request won't even reach your rewrites.
By the way, you may want to remove the Edge condition and simply redirect all browsers, to save them from guessing.

Route 53 - Special domain for a single page on existing server

I have a complex web app at example-app.com, hosting fully on AWS using ELB and Route 53 for DNS. It's a Rails app.
I'm running an experiment that I'm using in the rails app, at example-app.com/test. I want to set up new-domain-app.com, to point at example-app.com/test, and have the URL cloacked to always be new-domain-app.com. It's a single page site, so it shouldn't require any navigation.
I'm having a lot of trouble figuring out how to set up my DNS on Route 53 to accomplish this. Does anyone have good ideas on what this Route 53 configuration should look like?
AWS offers a very simple way to implement this -- with CloudFront. Forget about the fact that it's marketed as a CDN. It's also a reverse proxy that can prepend a fixed value onto the path, and send a different hostname to the back-end server than the one typed into the browser, which sounds like what you need.
Create a CloudFront web distribution.
Configure the new domain name as an alternate domain name for the distribution.
For the origin server, put your existing hostname.
For the origin path, put /test -- or whatever string you want prefixed onto the path sent by the browser.
Configure the cache behavior as needed -- enable forwarding of the query string or cookies if needed and any headers your app wants to see, but not Host.
Point your new domain name at CloudFront... But before you do that, note that your CloudFront distribution has a dxxxexample.cloudfront.net hostname. After the distribution finishes setting up (the "In Progress" status goes away, usually in 5 to 20 minutes) your site should be accessible at the cloudfront.net hostname.
How this works: When you type http://example.com into the browser, CloudFront will add the origin path onto the path the browser sends, so GET / HTTP/1.1 becomes GET /test/ HTTP/1.1. This configuration just prefixes every request's path with the string you specified as the origin path, and sends it on to the server. The browser address bar does not change, because this is not a redirect. The host header sent by the browser is replaced with the hostname of the origin server when the request is sent to the origin.
What you are trying to do is not possible. Route53 is a DNS system, and you can not configure a hostname (e.g. new-domain-app.com) to point to URL (e.g. http://example-app.com/test) using DNS.
However, you are probably using a wrong tool for the job. If example-app.com/test is indeed a simple, static, single page site, then you do not need to host it inside Rails app. Instead, you can host it on AWS S3 bucket, and then you can point new-domain-app.com to that bucket using Route53.
See the following for details:
http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html
http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/RoutingToS3Bucket.html
DNS knows about Domains, not url's. DNS simply converts names to IP addresses.
You can't do what you are asking for just using DNS and ELB, however, what you can do is have a seperate VHOST for new-domain-app.com that points to your example-app.com site and accomplishes what you want using some sort of redirection rule that only fires for new-domain-app.com.
I'm not sure that this qualifies as an SO question, and more likely is a serverfault question. Specifics about your webserver and OS platform would be helpful in getting more specific advice.
So here's some details:
You already have example-app.com setup and working
You create a CNAME entry pointing new-domain-app.com to example-app.com or you can make an A record pointing to the same IP. If you already have example-app.com pointing to a different IP address, then use a subdomain (test.example-app.com) to isolate it.
Setup a new vhost on your server that basically duplicates the existing vhost for new-domain-app.com. The only thing you need to change is the server name configuration.
Why does this work? Because HTTP 1.1 included the HOST header that browsers send along, and web servers use in vhosting to determine which virtual host to route an incoming request to. When it sees that the client browser wanted "example-app.com" it routes the request to the appropriate vhost.
Rather than having to do some fancy proxying, which certainly can be used to get to a similar result, you can just add a redirection rule that looks for requests for the host example-app.com and redirects those to example-app.com. In apache that uses mod_rewrite which people often utilize by putting rules in the ubiquitous .htacess file, but can also be done in nginx and other common web servers. The specifics are slightly different for each.

CNAME url on site transfered to

Is it possible to have the site you transfer to from a CNAME and 'A' record keep the name from the CNAME in the url? Example: Site 123.com has a CNAME called app pointing to abc.com. When I type in app.123.com, it transfers me to abc.com and keeps app.123.com in the url on the first page that I transfer to. But once I click anything on the page to move around within the page, the url reverts back to abc.com. Is it possible to have the app.123.com stay in the url while I move around. So instead of changing to abc.com/otherPage.php, it would stay app.123.com/otherPage.php?
Thanks for any help!
There are two different mechanisms at work here, DNS and HTTP.
When you use a URL containing app.123.com, that's looked up using DNS and gives the IP address that happens to be the same as the IP address configured for abc.com
But once you're viewing that page, the HTML of that page will determine how the links work, they may be absolute URLs including abc.com or they may be relative URLs, so behaviour could vary.
A site can be made to work under multiple aliases but it would need to use the request headers to detect the address used by the client and alter content accordingly.

How will the URL requested look when using vhost and url rewriting?

I have a small system (Coldfusion8, MySQL 5.0.88), which allows users to skin the main website depending on their prefrences.
This works all well, except for the URL still being ugly like so:
www.my_site.com/index.cfm?user=123456789
I now want users to have their own URL displayed and have read into vhost (I'm running Apache) on how to do this. I'm changing skins depending on the id provided in the URL. If I now setup my system to display:
wwww.users_selected_url.com
versus the above, I will have no way to check for the URL ID. I'm using this ID check a fair bit throughout the application to customize the page layout when rendering the page with Coldfusion.
Question:
When will the URL be reformatted? Will the page being loaded still be requested with the original URL, so Coldfusion can do it's stuff and only the page displayed to the user will be with his customized URL? How about if I also use URL-rewriting?
Thanks for some info!
You need to have a vhost setup to accept requests for the wwww.users_selected_url.com host, and the DNS needs to point to your server. In the vhost config, you can use the rewrite module to change the URL to /index.cfm?user=123456789, and this rewriting happens before the URI is handed off to cold fusion. You need to add this to your vhost config:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?users_selected_url.com$ [NC]
RewriteRule ^/$ http://www.my_site.com/index.cfm?user=123456789 [L,P]
This uses mod_proxy to proxy the request to http://www.my_site.com/index.cfm?user=123456789 when someone goes to http://www.users_selected_url.com/ in their browser.

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.

Resources