How do I stop other domains from pointing to my domain?

混江龙づ霸主 提交于 2021-02-17 21:55:08

问题


I recently found out that there are other domain names pointing to my website (that don't belong to me) and I was wondering how people can stop/prevent this from happening. I'm hosting this on peer1 using IIS and I'm using ASP.NET C#.

Can I use an HttpModule or some other code to reject domain names that aren't mine?

Is there a better way?


回答1:


You should activate name-based virtual hosting and only show your real website for the desired domain names. For all other names, you can display a suitable error message.

Details: Your webserver is contacted by its IP address. There is nothing you can do to stop that. Anyone can say, "connect to that IP address". For instance, anyone can register new domain names to point to your server's IP address. However, inside the request, there is a field Host with a name like www.example.com.

Upon receiving the request, your server may choose to inspect the Host field and deliver different content depending on that value. In the simplest case, the server ignores the field entirely and always prints out the same content. But in a more sophisticated set-up, so called "name-based (virtual) hosting", the server chooses the content depending on the hostname.

This is how shared webhosts work: There's a single server, but depending on the requested hostname it spits out a different website for each name.

Therefore, if you want to tie your server content to your hostname, you have to tell your server to produce your website only for your desired name, and to produce a different (error) website for all other cases.

In Apache this is trivial to configure, just check their documentation; for IIS I wouldn't know but I imagine it's equally simple.




回答2:


If your hosting environment is IIS and you have admin access to it. Set your default website to show an error page and then create a new site with the host header matching your domain to point to your website.




回答3:


This is my solution. It really works fast and solved my problem.

Insert this code in your .htacces

RewriteCond %{HTTP_HOST} !^www.higueyrd.com$
RewriteRule ^/?(.*) http://www.higueyrd.com/$1 [QSA,R=301,L]

Just put your domain.




回答4:


In IIS there is a setting called bindings that allows you to select which hostnames your website will respond to. This feature allows an instance of IIS to host mulitple websites on a single IP address.

If you want your site to only work for http://example.com/ and http://www.example.com/, you should set the bindings to only work for "example.com" and "www.example.com".

The exception here is if you are using SSL. If you are, IIS cannot determine the hostname and you will most likely have to use a dedicated IP address for your site. In that scenario, user608576's solution will work. Although, I would put that code in your Global.asax file:

<%@ Application Language="C#" %>
<script runat="server">
void Application_BeginRequest(Object sender, EventArgs args)
{
    HttpRequest request = HttpContext.Current.Request;
    HttpResponse response = HttpContext.Current.Response;

    if( (request.Url.Host != "example.com") && (request.Url.Host != "www.example.com") )
    {
        response.Clear();
        response.Write("Unauthorized domain name: " + request.Url.Host);
        response.End();
    }
}
</script>



回答5:


As a temporary fix you can do this . May be on home page load or BeginRequest .

if(!Request.Url.Host.ToLower().contains("mysite.com")){
  Response.Redirect("error.html");
}



回答6:


If i remember right when i last check my sites cpanel i saw a feature that stopped redirections to my domain if checked. I´m using Hostso as my host so check their test cpanel for it.

Hope it helps alittle atleast :)

Fredrik wirth




回答7:


if you want to handle in code then do it in Global.asax in BeginRequest as below

void Application_BeginRequest(object sender, EventArgs e)
{
    if (!context.Request.Url.Host.ToLower().Equals("www.mydomain.com"))
    {
        context.Rewritepath("/invalidpage.aspx");
    }
}

The other simple way is to specify a host headers in IIS for your website.

http://technet.microsoft.com/en-us/library/cc753195(v=ws.10).aspx Note: I am writing through my mobile so consider spelling mistakes



来源:https://stackoverflow.com/questions/6666719/how-do-i-stop-other-domains-from-pointing-to-my-domain

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!