简体   繁体   English

带有或不带有“ www”的域名

[英]domain name with or without 'www'

I have a domain eg 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. 我有一个域名,例如www.example.com,当人们在example.com中键入内容时,仍然可以访问它,但是不会自动在网址中添加“ www”。

But as for website like facebook, if you type in facebook.com, it'll automatically add that 'www', BEFORE loading the page for you. 但是对于象facebook这样的网站,如果您输入facebook.com,它将在为您加载页面之前自动添加“ www”。

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? 那么,当人们键入example.com时,如何使我的域名像facebook一样自动为他们添加www?


EDIT: Ok, so I need a redirect to the 'www' subdomain. 编辑:好的,所以我需要重定向到'www'子域。 Actually I'm using nodejs, which hosted on Amazon EC2, to serve the webpage instead of Apache HTTP. 实际上,我使用的是托管在Amazon EC2上的nodejs,而不是Apache HTTP,为网页提供服务。 So any equivalent of .htaccess in nodejs area? 那么,nodejs区域中的.htaccess是否等效? 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? 我想现在问题转向了更多面向nodejs的方法,事实证明它已成为该线程的冗余: 使用Express 3重定向所有请求?

Thanks all for your help. 感谢你的帮助。

you have to set your domain 301 permanent redirect in your control panel. 您必须在控制台中设置域301永久重定向。

if your website is hosted in CPANEL then 如果您的网站托管在CPANEL中,则

  1. GOTO -> Redirects in ( Domains Menu ) 转到->在(域菜单)中重定向
  2. Choose the type Permanent (301) 选择永久类型(301)
  3. choose your domain.com 选择您的domain.com
  4. www.domain.com in redirects to→ _ _ www.domain.com中的重定向至→ _ _
  5. check the box on Redirect with or without www 选中带有或不带有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 如果您的网站托管在PLESK中,请在程序级别或上面的plesk11.0.29版本中支持301永久

You can do all of this with a .htaccess file. 您可以使用.htaccess文件来完成所有这些操作。

https://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F 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. 将其添加到主机上名为.htaccess的文件中,但将其设置为您希望主页成为的URL。

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. 要制作.htaccess文件,您总是可以进入FTP,上传一个空的.txt文件,用记事本打开它,放入上面的代码行,然后将其重命名为.htaccess。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM