Jump to content

Redirect Non-www Traffic to www in Apache?


Recommended Posts

Posted (edited)

Hi all,

 

We've had a new website developed for us by an external company. There seems to be an issue with fonts and icons not loading on initially visiting the website, which then go on to work when a link is clicked.

 

The developers of the theme suggested that I redirect non-www traffic to www in Apache itself. After googling up just what on earth that meant, I've brewed up the following:

 

[font=arial][/font]
[font=arial]    ServerName mysite.co[url="http://longhill.org.uk/"].[/url]uk[/font]
[font=arial]    Redirect permanent / [url="http://mysite.co.uk/"]http://www.mysite.co.uk/[/url][/font]
[font=arial][/font]
[font=arial]
[/font]
[font=arial][/font]
[font=arial]    ServerName [url="http://www.mysite.co.uk"]www.mysite.co.uk[/url][/font]
[font=arial][/font]

 

Will this achieve what I want to do or no?

 

Thanks any and everyone!

Edited by JRA
Posted
That should work correctly.

 

I use the same to force to https

 

Ta! I'll stuff that in. :)

 

If it's a brand new website shouldn't it be redirecting to the HTTPS version of the site (https://www.mysite.co.uk)?

 

Well the site itself I'm not sure entirely needs that, but the remote desktop and portal sites etc do have ssl. I've got the wildcard cert so meh, might plumb it in.

 

Thanks much to you both.

  • 2 months later...
Posted

Redirect permanent / http://www.mysite.co.uk/

Will this achieve what I want to do or no?

 

Only for the bare URI, no pages or other assets. You don't need a second virtualhost either.

 

Better:

 


   ServerName mysite.co.uk
   ServerAlias www.mysite.co.uk

   RewriteEngine on
   RewriteCond "%{HTTP_HOST}" "!^www\.mysite\.co\.uk" [NC]
   RewriteCond "%{HTTP_HOST}" "!^$"
   RewriteRule "^/?(.*)" "http://www.mysite.co.uk/$1" [L,R=301]

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...