301 Rewrite domain.co.uk to www.domain.co.uk like the search engine friendly developer you are!

/ Published in: Apache
Save to your folder(s)

Rewrite your urls for domain.co.uk to www.domain.co.uk including full url

Copy this code and paste it in your HTML
  1. In your Virtual Host declaration add a ServerAlias under your ServerName declaration for example you would have
  3. ServerName www.domain.co.uk
  4. ServerAlias domain.co.uk
  6. This on it's own would mean that visitors will be sent to your site with or without the www. prefix.
  8. What we can do is take the url they entered for example domain.co.uk/news/wow-look-at-this
  9. and rewrite it to
  10. www.domain.co.uk/news/wow-look-at-this
  12. All you need to do is; within your .htaccess file for the site add the following at the top
  14. RewriteCond %{HTTP_HOST} ^domain\.co.uk
  15. RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [R=301,L]

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.