How to redirect with “www” URL's to without “www” URL's or vice-versa?

后端 未结 8 2048
死守一世寂寞
死守一世寂寞 2020-12-08 05:15

I am using ASP.NET 2.0 C#. I want to redirect all request for my web app with \"www\" to without \"www\"

www.example.com to example.com

Or

example.co

8条回答
  •  执笔经年
    2020-12-08 06:00

    This is usually handled by your web server directly in the configuration. As you mentioned, the .htaccess file does this for the Apache web server -- it has nothing to do with PHP. Since you're using ASP, it's a near certainty your server is IIS. I know there is a way to set up this direct with IIS, but I don't know what it is. You may be aided in your search by knowing you should be googling for things related to "IIS redirect", not "ASP redirect".

    That said, you CAN do it in PHP, and almost certainly ASP as well, but you'll have to have hitting any URL at the wrong domain invoke an ASP script that performs the redirect operation (using appropriate API calls or by setting headers directly). This will necessitate some URL rewriting or somesuch on the part of the server so that all URLs on the wrong host are handled by your script... just do it directly at the server in the first place :)

提交回复
热议问题