.htaccess + subdomain + redirect - .htaccess

Just wanted to know how we can redirect the subdomain to domain.
I have two domain which in pointing to my rails application and a subdomain
www.xyz.com
www.xyz.info
example.xyz.com
Now when the user access www.xyz.info the example.xyz.com page should open up but the address bar should be www.xyz.info.
So is it possible to redirect?
Thanks
Abhi

One approach should be to use a reverse proxy, using mod_proxy. In the configuration of www.xyz.info put
ProxyPass / http://example.xyz.com/
However, I think it would be much easier to just deploy the rails application twice, i.e. put the configuration that you have in example.xyz.com also into www.xyz.com.

Related

Point client domain to our subdomain

We are currently developing a CMS for our clients. We would like to host all their pages on our server like this:
https://www.example.com/client1website or https://www.example.com/client2website.
Is there a simple way to redirect content from https://www.example.com/client1website to https://www.theirdomain.com?
I know that Heroku or Wix work in a similar way, but I don't really know how to achieve it. Setting the CNAME for www to https://www.exmaple.com/client2website is probably not enough?
Godaddy can do https://www.client1website.example.com to https://www.theirdomain.com
But otherwise they are going to need to stop at your server first since you are pointing them down into your directory
You can redirect using status code 308

domain name with or without 'www'

I have a domain e.g. named www.example.com, when people type in example.com, it still can be accessed, but won't automatically add that 'www' to the url.
But as for website like facebook, if you type in facebook.com, it'll automatically add that 'www', BEFORE loading the page for you.
Probably I didn't explain it well, but guess you see the difference and get my point anyway.
So how can I make my domain acts like facebook, when people type example.com, it'll automatically add that www for them?
EDIT:
Ok, so I need a redirect to the 'www' subdomain. Actually I'm using nodejs, which hosted on Amazon EC2, to serve the webpage instead of Apache HTTP. So any equivalent of .htaccess in nodejs area?
I guess now the question shifts to more nodejs oriented, and it turns out it becomes a redundant of this thread:
Redirect all requests using Express 3?
Thanks all for your help.
you have to set your domain 301 permanent redirect in your control panel.
if your website is hosted in CPANEL then
GOTO -> Redirects in ( Domains Menu )
Choose the type Permanent (301)
choose your domain.com
www.domain.com in redirects to→ __
check the box on Redirect with or without www
finally CLick ADD
if your website is hosted in PLESK then
do it in your program level
or
plesk11.0.29 version above supports the 301 peramanent
You can do all of this with a .htaccess file.
https://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://mt-example.com/
Add this in a file named .htaccess on your host, but set it to the URL you want your main page to be.
To make a .htaccess file, you can always go in FTP, upload an empty .txt file, open it with notepad, put in the lines of code above, then rename it to .htaccess.

Cakephp .htaccess : multiple domains pointing to one app

I am working on one cakePHP application.
Now i want to configure my main domain (www.example.com) to be accesses via 'www.xyz.com' or 'www.bcd.com'.
For this i will add the CName record in the 'www.xyz.com' or 'www.bcd.com' as 'www.example.com' then xys.com & bcd.com will point to the example.com.
But now on the xyz.com & bcd.com i can see the content of example.com, but whenever i click on any link it gives me 'URL NOT FOUND' Error.
So i tried lots of .htaccess rules but it is not working.
It is similar to the bloggers custom domain pointing. I need the same thing to be applied for my application.
Can anybody tried this before?
This isn't entirely an .htaccess issue - you need to first edit the server name in your web servers configuration file to serve not only example.com, but also requests coming in from xyz.com and bcd.com.

1 domain.. 2 server and 2 applications

i have a site like twitter.com on server one and on server two i have forum, which path is like domain.com/forum
on server one i wanted to implement wild card dns and put main domain on it. but on server two i wanted to keep forum separate, i cant give sub-domain forum.domain.com, because all its links are already put in search engines and link back to domain.com/forum.
so i was wondering, how can i put domain and wild card dns on server one and still able to give path on server 2 for domain.com/forum (as sub-folder).
any ideas?
do you think htaccess can do that job? if yes, then how?
You could use htaccess and mod_rewrite so domain.com/forum actually displays pages from forum.domain.com.
Maybe something like this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule domain.com/forum/(.+) forum.domain.com/$1
Easy - use a proxy! If you like apache you will love apache mod_proxy for your purpose.
<VirtualHost *:80>
ServerName maindomain.com
ServerAlias *.maindomain.com
# insert document root and general settings for this domain here
# ...
ProxyPass /forum http://forumdomain.com
ProxyPassReverse /forum http://forumdomain.com
ProxyPassReverseCookieDomain forumdomain.com maindomain.com
</VirtualHost>
This configuration makes apache do a HTTP-request to your internal domain (forumdomain.com) without notifiying the users browser of the internal location. Your Forum will be accessable at http://*.yourdomain.com/forum. Cookies and headers the forum sents will get rewritten accordingly and Search-engines will not take notice of your backend-server.
You can read more about it at http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
Should you need to rewrite reference sin your html (href, src ...) you might google on "mod_proxy_html".
A solution like this could of course be build with other intelligent proxyservers like squid as well. You can use it to map any content from "backend servers" to your public domain.
Make sure routing is OK or set up a host-entry for your internal domain (forumdomain) with a internet ip-addresse 192.168 ...
Enjoy your site and give feedback how worked out :)
p.s.: a "RewriteRule" directive can potentially do the same thing for you but the rdirect will be visible (and executed) by the client unless you specify the "P", foricng it to do an internal proxy request. If available I would prefer the mod_proxy though as it is more versatile and allows for more configuration.
If you use a proxy on server 1 pointing to server2, you will increase the load on server 1, since all traffic will be routed through it. Besides, if server 1 goes down, nobody will be able to reach server 2 either. Of course it is possible though, but these things are to be considered.
I would suggest setting up a supdomain for server 2 anyway, like forum.domain.com, and on server 1 you set up a 301 redirect from domain.com/forum to forum.domain.com using mod_rewrite from htaccess. Using that technique, you can even redirect calls to specific links to their corresponding page on server 2. Search engines will follow the 301 and they will eventually update the index.
You can use a 301 redirect to make sure the search engine update their index with your new urls like so:
RewriteRule domain.com/forum/(.*) http://forum.domain.com/$1 [R=301,L]
If you've got two servers you don't really have much choice but to use a redirect (ideally a 301 Permanent redirect) to move users from domain.com/forum to forum.domain.com.
The only other way to do it would be to put a reverse proxy in front of those two servers, which reads the URL and internally directs the query to the right server, but that's then an extra piece of hardware.

DNS- Route DNS for subfolder to different server?

LEt's say I want to have a subfolder called- http://www.foo.com/news/ but I actually want that news folder on a different server. I realize it can be done easily with subdomains, but I was really hoping for the subfolder thing.
Is it possible? How?
The only real way to it is with a reverse proxy ( Or a webserver acting as a reverse proxy ) between you and the outside world that knows what IP address each folder is in.
Its not possible to just make something, for example have google.com appear at http://foobar.com/google/ because the browser won't route to the IP address ( lack of information ).
You can fake that effect with a fullpage IFrame or Other frameset system, but that's rather dodgy.
If you are using apache, you can set this up with mod_proxy. More details can be found here:
Mod_Proxy(1.3) Manual
Mod_Proxy(2.0) Manual
Apache Tutor.org guide
For Apache the following entries in httpd.conf are needed:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ProxyPass /news http://newsserver.domain.com/news
ProxyPassreverse / http://newsserver.domain.com/
Yes, there is a setting in IIS which lets you point a subfolder to a different site. So make the sub folder a virtual directory on your site, and then in the properties of the virtual directory choose the option for 'A redirection to a URL'... in it specify your other site.
Of course, this is assuming your are using IIS. There should be something similar available to use in whatever web server you are using.
It can't be done with DNS because the domain name is only the *.example.com of the address.
It can be done by configuring a proxy on your www machine to pass all requests for /news to another server. It's very easy to do with apache but I don't remember all the details at this moment.
DNS resolution happens at the domain level. DNS doesn't have any knowledge of URLs or folders so your name will always point to the same server. You can make that server actually retrieve the information from another one or redirect to another one but that's not very satisfactory I'd say.

Resources