0

Currently users can access the ourdomain.com BUT i want those visitors to be redirected to www.ourdomain.com

What is the best solution? - We have plesk, linux, apache server running php

Thanks

ServerDown
  • 362
  • 1
  • 2
  • 8

4 Answers4

1

What the best solution is you'll have to decide -- it does amongst other things come down to what technologies you're most able to maintain.

You can do the redirect via Apache's .htaccess, if this isn't disabled on your server (it is most often available, but sometimes its disabled for a slightly better performance / security). Here is a syntax example, and you could google htaccess for more.

You can also do the redirect via PHP. The syntax for the redirect itself would be something like:

header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.yoursite.com/');

Note that you'll need your PHP logic to discern between requests that come in with or without 'www.', and only send the header for those without 'www.'. If you're using some sort of 3rd party PHP CMS, then you probably shouldn't change its PHP code.

One last thing, if you care about search engine ranking, and you have previously had your site indexed both with and without 'www.', then you should fix that. In Google, log in to Google's Webmaster Tools, and set the canonical URL to the one you prefer, with or without www. For other search engines, inbound links etc, it could be beneficial to contact those who link to you, and have them update their links.

1

There are a couple of options:

if you have a seperate directory/section for ourdomain.com you can use an index.html to redirect your users

<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="REFRESH" content="0; URL=https//www.ourdomain.com">
<title>HTML REDIRECT</title>
</head>
<body>
</BODY>
</HTML>

you can also use a php program:

header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.yourdomain.com");
exit();

This has to be the first lines in your code to be part of the html header

Francois Wolmarans
  • 1,570
  • 10
  • 14
0

Not sure if you can, but perhaps mod_rewrite?

churnd
  • 3,977
  • 5
  • 33
  • 41
0

With mod_rewrite

RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Corey Hart
  • 115
  • 4