Domain 301 permanent redirect
Well, for many people it’s not, but there are some thoughts, and some of them you can read more about on the dedicated no-www.org web site.
A thought can be to prevent duplicate content penalty on search engines, though it is hard to say if this is still a problem.
I like to use the domain.com, and rather keep www.domain.com pointing to it permanently, it’s easier to distribute, remember, and keeps it simple. Some people might want to go the other way, pointing domain.com to www.domain.com, that is of course also an option.
To forward a domain properly and permanently, you should use the rewrite module if using apache, I think IIS has its own way of dealing with it.
Here is the rewrite lines to put into either .htaccess or directly in the domain 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 nice web site.
Some 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/");
Leave a Reply
Welcome to Thronic.com
Search this Site
Miscellaneous Links
Recent Articles
- Google-like search suggestion tool
- Linux Bash Color
- Resize a div layer with javascript
- Moving a div layer with javascript
- Web Galaxy » A sci-fi browser game
- Windows 7 on Asus Eee 900 PC
- IE and PHP sessions
- Wordpress 2.8.6 Spell Check Languages
- Reset MySQL Root Password
- Linux hosts file
- IdleGuard
- Column count in SQL
- String encryption in PHP
- Alphanumeric Captcha values in PHP
- Your own numeric Captcha in PHP
