English 中文(简体)
Redirect from http://sitename.com to http://www.sitename.com
原标题:Redirect from http://sitename.com to http://www.sitename.com

我正在使用协会。 NET 4. . http://www.sitename.com。

这样做的最佳方式(和选择方式)是什么?

我的网址也在索引上。 我怎么能够阻止这一点。

最佳回答

可在<代码>上进行简单核对。 * E/CN.6/2009/1。

    protected void Page_Load(object sender, EventArgs e)
    {
        string serverName = HttpUtility.UrlEncode(Request.ServerVariables["SERVER_NAME"]); 
        string filePath = Request.FilePath;
        if (!serverName.ToLower().StartsWith("www.")) 
            serverName = "www." + serverName; 
        Response.Redirect("http://" + serverName + filePath); 
    }

或者,你可以在离散文件上添加以下内容:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc] 

http://www.domain.com和

问题回答
<rule name="Redirect to www">
  <match url="(.*)" />
  <conditions>
    <add input="{SERVER_PORT}" pattern="443" negate="true" />
  </conditions>
  <action type="Redirect" url="https://www.serdardemir.net/{R:1}" />
</rule>

you can use url rewrite add this rule to rules tag

<rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^yoursite.com$" />
          </conditions>
          <action type="Redirect" url="http://www.yoursite.com/{R:0}" redirectType="Permanent" />
        </rule>

This code worked me. Add this in rules section of your web.config file





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!