PDA

View Full Version : Redirecting my website 301 in HTML?



wtfmancmon
23 Feb 2007, 11:32 PM
i have done a little googling and found some scripts for putting a 301 redirect

i have a .net and a .com of the same website, i want to redirect the net so google doesnt pass me by in search rankings.

Redirect in ASP
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently" Response.AddHeader "Location", " http://www.new-url.com"
>

~~~~~~~~~~~~~~~~~~

Redirect to www (htaccess redirect)

Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Please REPLACE domain.com and www.newdomain.com with your actual domain name.

Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

~~~~~~~~~~~~~~~~~~~~~

first i dont know how to create a .htaccess file.

i started dreamweaver and a new .ASP document and posted the code in, and it did nothing...

does it have to be called index.asp?

i just want to redirect using html or explained in more detail, thanks everyone!

Alan
24 Feb 2007, 11:50 AM
OK let's see... As far as I know you can't redirect using just HTML. HTML is only a document language for displaying data, nothing got to do with the workings of a website or anything complicated.

To create a .htaccess file simply create a new notepad document and save it as .htaccess and under all file types. If your computer doesn't allow you to do this, log into your server and upload a file called x.htaccess or something and then just rename it to .htaccess. Problem solved there.

The .htaccess will only work on an apache server (maybe only on a Linux system, i'm not too sure), so if you have one, this would be the best way of doing it. If your talking about using ASP then I would imagine that you have a windows server and not a Linux one.

As for using ASP or any other server scripting language, scripts will only execute the code that is contained within their files when those files are called. So yes, it would have to be an index file (assuming the code works).

Now onto the how to sort it out...

There are a few ways you can redirect your .net to your .com.

I use GoDaddy.com Hosting and they allow you to set domains as a referrer to another domain. Handiest way to do it by far.

I also tried using PHP to redirect the user based on what url was entered.
First I added my .net to my server as an alias domain name. (Both domain names would work exactly the same) Then I added this to the header file of my website: It's PHP


<?php
$domain_ext = '.net';
$current_addr = $_SERVER['SERVER_NAME'];
$current_domain_ext = substr($current_addr,strlen($current_addr)-4,4);
if($current_domain_ext == $domain_ext)
{
header("location: http://www.mydomain.com");
}
?>

Hope that helps.

Oh and one more thing. You can do a redirect using JavaScript but I wouldn't advise it because if a user's JS is turned off, the redirect wouldn't work. But if you were feeling extremely lazy, you could put in a JavaScript redirect and provide a text link if there JS was turned off.



<script language="JavaScript">
if(window.location == 'http://www.mydomain.net' || window.location == http://mydomain.net')
{
window.location = 'http://www.mydomain.com';
}
</script>


It would be something like that. JS ain't my specialty so it would require abit of digging on your part.