Domain 301 Permanent Redirect
Here are the Apache rewrite lines to put into either .htaccess or directly in the domain configuration file depending on your setup.
This rule will point www. to domain.com
RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
You can learn more about rewriting rules from this and the official(regex) web site.
Below are alternative ways to redirect as well if you are doing it from another webhost and/or scripts.
If you need to redirect from a PHP script:
<? Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location: http://www.new-url.com" ); ?>
If you need to redirect from an ASP script (VBScript):
<%@ Language=VBScript %> <% Response.Status="301 Moved Permanently" Response.AddHeader "Location","http://www.new-url.com/" %>
If you need to redirect from an ASP.NET script:
<script runat="server"> private void Page_Load(object sender, System.EventArgs e) { Response.Status = "301 Moved Permanently"; Response.AddHeader("Location","http://www.new-url.com"); } </script>
If you need to redirect from a ColdFusion script:
<.cfheader statuscode="301" statustext="Moved permanently"> <.cfheader name="Location" value="http://www.new-url.com">
If you need to redirect from a JSP script:
<% response.setStatus(301); response.setHeader( "Location", "http://www.new-url.com/" ); response.setHeader( "Connection", "close" ); %>
If you need to redirect from a PERL (CGI) script:
$q = new CGI; print $q->redirect("http://www.new-url.com/");
Force SSL with dynamic pattern to match all query strings (rewrite/.htaccess):
RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]