Mobile app version of vmapp.org
Login or Join
Tiffany637

: Force www to always show in address bar? I have created a website for a client (my first freelance job!) and my client is generally happy, however they want the address bar to always show

@Tiffany637

Posted in: #AspNetMvc #Azure #Domains

I have created a website for a client (my first freelance job!) and my client is generally happy, however they want the address bar to always show the portion, even if it isn't typed.

Is this possible? I have purchased the domain through 123-reg and am hosting the website on Azure (as an Azure Website). I am guessing I need to add an A record to the DNS settings, would this be correct? Or is it a setting I need to change on Azure? Or something on the web.config file?

The site has been created with ASP.Net MVC4.

Thanks

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Tiffany637

3 Comments

Sorted by latest first Latest Oldest Best

 

@Radia820

Redirect non-www to www in MCV4

Edit global.asax and add:

protected void Application_BeginRequest (object sender, EventArgs e)
{
if (!Request.Url.Host.StartsWith ("www") && !Request.Url.IsLoopback)
{
UriBuilder builder = new UriBuilder (Request.Url);
builder.Host = "www." + Request.Url.Host;
Response.StatusCode = 301;
Response.AddHeader ("Location", builder.ToString ());
Response.End ();
}
}

10% popularity Vote Up Vote Down


 

@Ravi8258870

If you cannot change your Apache configuration, you can try wwwizer.com (top of the page) where you point the NAKED domain to the IP address of WWWizer, and your WWW subdomain to your server. This will redirect all requests to the WWW subdomain.

10% popularity Vote Up Vote Down


 

@BetL925

Yes, you can redirect urls without the www to then include them. How to do so depends on your host. Some hosts have an option for this and you can just press a button to make it happen.

Most host serve both www and no-www sites from the same directory on an Apache server. In this case you will need to use rewrite rules to do it.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ www.%{HTTP_HOST}/ [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme