Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Currently users can access the BUT i want those visitors to be redirected to

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


share|improve this question
Why? – Jan Jungnickel Oct 9 '09 at 10:07
duplicate?… – warren Oct 9 '09 at 11:58

There are a couple of options:

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

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="REFRESH" content="0; URL=https//">
<title>HTML REDIRECT</title>

you can also use a php program:

header("HTTP/1.1 301 Moved Permanently");

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

share|improve this answer

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');

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.

share|improve this answer

Not sure if you can, but perhaps mod_rewrite?

share|improve this answer

With mod_rewrite

RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$$1 [R=301,L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.