[英]How to redirect www.example.com to example.com?
My MVC4 app is hosted on Azure (shared website) and works fine at exaple.com. 我的MVC4应用托管在Azure(共享网站)上,并在exaple.com上运行良好。
I'd like to redirect www.example.com to example.com, but it reports 404 error if accessed at www.example.com. 我想将www.example.com重定向到example.com,但是如果访问www.example.com,它将报告404错误。
What should I add and is it the proper way to solve this problem? 我应该添加什么,这是解决此问题的正确方法吗?
I don't think it's DNS problem as I have asked it on serverfault . 我认为这不是DNS问题,正如我在serverfault上提出的那样 。
I have tried to redirect via Web.config: 我试图通过Web.config重定向:
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="WWW Rewrite" stopProcessing="true" enabled="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www[.](.+)" />
</conditions>
<action type="Redirect" url="http://{C:1}/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
But it doesn't work. 但这是行不通的。
You must have a DNS record for both: www.mysite.com and mysite.com, either A or CNAME. 您必须同时具有以下两者的DNS记录:www.mysite.com和mysite.com(A或CNAME)。 Then, on the web server you should setup a "301" redirect that would redirect all requests from www.mysite.com to mysite.com.
然后,在Web服务器上,您应该设置“ 301”重定向,该重定向会将所有请求从www.mysite.com重定向到mysite.com。
If you don't mind people using both, then just a CNAME record in your DNS zone should do the trick: 如果您不介意同时使用这两种方法的人,那么只需在DNS区域中的CNAME记录即可:
www IN CNAME mysite.com
I think there is a way to register with Google and tell it to always use one or the other to index your site. 我认为有一种方法可以向Google注册,并告诉它始终使用其中一个来索引您的网站。
In addition to the rewrite section in Web.config both domain names (example.com and www.example.com) have to be configured in Azure as custom domains. 除了Web.config中的重写部分外,还必须在Azure中将两个域名(example.com和www.example.com)配置为自定义域。
Then everything works as desired. 然后一切都会按需工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.