1

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.

Community
  • 1
  • 1
kakacii
  • 728
  • 3
  • 10
  • 24
  • possible duplicate of [redirecting www.subdomain.example.com to subdomain.example.com](http://stackoverflow.com/questions/2909600/redirecting-www-subdomain-example-com-to-subdomain-example-com) – Oliver Charlesworth Jul 20 '13 at 02:57
  • here is a great guide on how to redirect using several web servers including nodejs: http://redirect-www.org/#nodejs – diegoubi Apr 26 '16 at 23:03

2 Answers2

1

you have to set your domain 301 permanent redirect in your control panel.

if your website is hosted in CPANEL then

  1. GOTO -> Redirects in ( Domains Menu )
  2. Choose the type Permanent (301)
  3. choose your domain.com
  4. www.domain.com in redirects to→ __
  5. check the box on Redirect with or without www
  6. 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

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
Ramnath
  • 193
  • 7
0

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.