redirect, rewrite, alias - which one?

hello.  I have a need to redirect a site, say www.somesite.com/somedir to www.somesite.org/somedir

I have a rewrite rule in place now to get the users from http to https
I also have a redirect in place now to get the users to the write somedir if they do not add it.
These work.

Various iterations trying to get them going from one subdomain to another is not working.  What am I missing?  thanks.
bongiosAsked:
Who is Participating?
 
Erdinç Güngör ÇorbacıConnect With a Mentor PHP Development Team LeaderCommented:
You can use 3 methods for 301 redirection

- Using the PHP header() function if your webserver supports PHP.
- Using the mod_rewrite functionality of Apache servers.
- Using built-in forwarding if your host provides it.

For first one ;

add this to the beginnings of the pages at your old domain.  (better include from a file )

<?php
 if(stristr($_SERVER["HTTP_HOST"], 'www')){
  header("HTTP/1.1 301 Moved Permanently");
  header("Location: http://mynewwebsite.com/" . $_SERVER["REQUEST_URI"]);
  exit();
  }
?>

Open in new window


code above sends the visitor from

http://www.myoldsite.com/detail.php
to
http://www.mynewsite.com/detail.php

as you can see not just domain but either page data is being used from url.
And exit() is important to make sure the rest of code is not executed before redirection.

Second way is using htaccess. -i prefer this one-

put lines below in a file named .htaccess (cant rename to this in windows rename after ftp if needed)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^myoldsite\.com [nc]
RewriteRule (.*) http://www.mynewsite.com/$1 [R=301,L]

if you need to carry Query Strings you can use QSA in [] at end of last line.

For more diggin you may consider taking a look at these pages ;

http://www.google.com/support/webmasters/bin/answer.py?hlrm=tr&answer=93633
http://www.bigoakinc.com/seo-articles/301-direct-Google.php

good luck :)

BTW : To test any 301 redirection, make sure you clear your browser's cache first! Otherwise, you won't see if it worked or not.
0
 
bigg_oilCommented:
you must edit your httpd.conf file

example
Listen 80
NameVirtualHost *

<VirtualHost *>
ServerName www.domain.com
DocumentRoot /home/httpd/htdocs/
</VirtualHost>

<VirtualHost *>
ServerName subdomain.domain.com
DocumentRoot /home/httpd/htdocs/subdomain/
</VirtualHost>

Open in new window


also setup a CName in dns records

http://content.websitegear.com/article/subdomain_setup.htm
0
 
Tyler LaczkoCommented:
you can use a JS or PHP script to do it.

<?php
header("Location: othersite.org.com");
?>
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
bongiosAuthor Commented:
I have edited the httpd.conf but as I said, the results were not as expected.
I do not have access to dns records, but will suggest that do to the admin there.

Where would the JS or PHP script be placed for it to run?

thanks much all.
0
 
Erdinç Güngör ÇorbacıPHP Development Team LeaderCommented:
Best way of doing this without losing Pagerank (if its important) is doing a 301 redirect.

Write me down if you need more help... bb
0
 
bongiosAuthor Commented:
Erdincgc,
I'd like more info on this, please.
thanks..
0
 
Erdinç Güngör ÇorbacıPHP Development Team LeaderCommented:
Hi! Do you have any other  questions upon my last answer?
0
 
bongiosAuthor Commented:
have not yet implemented -- will try the 301 this weekend.  Thanks so much!
0
 
bongiosAuthor Commented:
I apologize for not awarding the solution. Extreme oversight on my part.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.