Forum Moderators: phranque
I've been doing searches trying to figure out how to use a 301 redirect.
What I'm trying to do, is moving olddomain.com to newdomain.com. Problem is, newdomain.com has completely new content as well, and it differs greatly from olddomain.com.
I'm guessing
redirect 301 / http:// www. newdomain. com/
wouldn't be very effective since that redirect assume the content on newdomain.com is the same as on olddomain.com.
When it comes to apache and .htaccess I'm completly blind. I haven't done a redirect before, so please treat me as a newbie. ;)
The web server I'm redirecting from is running Apache/2.0.52 (Fedora) with mod_rewrite enabled (as far as I could find out).
Thanks for any suggestions you might have!
The code you specified will as you say redirect everything for the old domain to the same page on the new domain. However, before suggesting any solutions, you should think about exactly what you are trying to achieve with the redirection.
If the content and is completely different then you can't map the old pages to a new equivalent, so would you like to redirect everything to the home page, or something else?
If the content is similar and there are equivalent pages on the new site, I assume you want to map to the closest page on the new site. If so, what does your file structure look like for the old and new sites?
Finally, are you using any server-side technology to serve the pages (PHP, ASP, Perl etc.) backed by a database? If so, you may well find it better to use that to create a custom 404 page which silently redirects to the most appropriate new page as determined by a database search.
Thanks very much for replying!
What I'm trying to achieve by a redirect is also updating the search engines. The old web page has high rankings at Google and other search engines. When people search for a specific keyword, the result might point to olddomain.com/document.html. Since "document.html" no longer exist, I'd like the visitor to be redirected to the main page of newdomain.com
So, I want all visits to any web page on olddomain.com to be redirected to newdomain.com. The content on newdomain.com is the same topic as olddomain.com, but completly different.
The file structure on the old web site was pretty simply (and strange). All the files were in the root directory. And strangely enough, some documents had the very same names, only capitalized. Such as index.html was in Norwegian and INDEX.html was in English. The new site has been devided into subdirectories.
The old pages were horrible and i desperate need of a redesign. :)
I am using PHP basically only to
<?include 'file.php';?> .. The web site is not database backed. Even if I wish it was. Learning MySQL and PHP is on my "to-do list".
(Btw. PHP and MySQL Web Development 3rd edition is not a book for newbies like me!) ;)
If you simply want to redirect all the pages on your old domain to the new domain then a couple of lines in your .htaccess will suffice. But you should consider mapping similar pages if you are going to use a 301 redirect. The 301 is telling everyone, including search bots, that your page has been renamed.
If you rename all of your old-domain/pages.html to new-domain/index.html you quite possibly run the risk of creating duplicate content. You should also consider that all of your new pages will be essentially starting from scratch and will have to move thru the SERPs on their own merit. That will take time. I would sugggest you not take that approach.
The following code could be used to rename old page to new page name where the page names are unchanged.
Options +FollowSymLinks
RewriteEngine on
# The left side captures the request and stores it in $1.
# The right side redirects to the newdomain and reinserts the original
# file name at the location of the variable $1
# R=301 defines this redirect as Permanent.
# The L flag stops any further rewriting.
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
I understand that this doesn't exactly help, since you've indicated that your new pages do not share the same name as the old pages. In that case it is still better to rewrite each old file to a new file wherever possible. That means of course that your .htaccess file will be a little more complex.
Your rewrite rules for individual file names will look like this:
RewriteRule ^oldfile\.html$ http://www.newdomain.com/directory/newfile.html [R=301,L]
These rules would be placed in the .htaccess file of the old domain.
Something to think about, whatever you do will probably result in at least a blip on your SERPs. If you do this correctly that should be a minor blip.
Since "document.html" no longer exist, I'd like the visitor to be redirected to the main page of newdomain.com
The direct answer to this question is:
RewriteEngine ON
RewriteRule (.*) http://www.newdomian.com/ [R=301,L]
You may or may not need:
Options +FollowSymLinks
You may or may not need:
AllowOverride FileInfo
These are dependent on your host configuration.
If you need both, your end file will end up looking like this:
Options +FollowSymLinks
AllowOverride FileInfo
RewriteEngine ON
RewriteRule (.*) http://www.newdomian.com/ [R=301,L]
Otherwise, just turning the engine on and setting the rule should be fine:
RewriteEngine ON
RewriteRule (.*) http://www.newdomian.com/ [R=301,L]
The main difference between this and the example grandpa gave, is his will redirect to the specific location of the old file on the new domain. (See http://www.newdomain.com/$1) The $1 will transfer the information (file path) stored in the (.*) variable to the end of the new domain URL. By removing this, all old pages will be redirected to the main page of the new domain.
This is just a direct answer to the question. It should in no way replace the very valid points raised by encyclo and grandpa.
Justin
Added: I would recommend staying away from serving valid content after serving a 404 error... It could be SE death. (Can't tell if that is what encyclo was saying to do or not.)
I would recommend staying away from serving valid content after serving a 404 error... It could be SE death.
You're quite right for clarifying that: the idea of a custom 404 page would be to:
1. capture the page request,
2. determine whether a page on the new site corresponds to the request,
3. If yes, use a 301 permanent redirect to that page, or
4. If not, to issue a 404 Not Found and display a site map or equivalent.
So, I'm guessing the .htaccess will be something like this?
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^oldfile\.html$ http ://www.newdomain.com/directory/newfile.html [R=301,L]
The last line repeated for each .html file I want to redirect, and that's basically it? :)
Correct me if I'm making a mistake here. ;)
--
Fred
Options Indexes FollowSymLinks Includes ExecCGI
AddType application/x-httpd-cgi .cgi
AddType application/x-httpd-cgi cgi
AddType 'text/html; charset=ISO-8859-1' .html
AddHandler server-parsed .html
XBitHack full
I didn't make this and I have no idea what it does. Should it be safe to overwrite this? :)
--
Fred
Options Indexes FollowSymLinks Includes ExecCGI
AddType application/x-httpd-cgi .cgi
AddType application/x-httpd-cgi cgi
AddType 'text/html; charset=ISO-8859-1' .html
AddHandler server-parsed .html
XBitHack full
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^index\.html$ http ://www.example.com/index.php [R=301,L]
RewriteRule ^nsr\.html$ http ://www.example.com/index.php [R=301,L]
RewriteRule ^NSR\.html$ http ://www.example.com/index.php [R=301,L]
RewriteRule ^styret\.html$ http ://www.example.com/om_ringen/styret.php [R=301,L]
RewriteRule ^avdelinger\.html$ http ://www.example.com/om_ringen/avdelinger.php [R=301,L]
RewriteRule ^oppdrett\.html$ http ://www.example.com/avl_oppdrett/vis_oppdrett.php [R=301,L]
RewriteRule ^kattunger\.html$ http ://www.example.com/avl_oppdrett/vis_kull.php [R=301,L]
This resulted in a Internal Server Error. Did I do something wrong, or doesn't the Apache server support what I'm trying to do? :)
--
Fred
It might be something simple, like a line space. EG:
Options Indexes FollowSymLinks Includes ExecCGI
AddType application/x-httpd-cgi .cgi
AddType application/x-httpd-cgi cgi
AddType 'text/html; charset=ISO-8859-1' .html
AddHandler server-parsed .html
XBitHack full
RewriteEngine on
RewriteRule ^index\.html$ http ://www.example.com/index.php [R=301,L]
RewriteRule ^nsr\.html$ http ://www.example.com/index.php [NC,R=301,L]
RewriteRule ^styret\.html$ http ://www.example.com/om_ringen/styret.php [R=301,L]
RewriteRule ^avdelinger\.html$ http ://www.example.com/om_ringen/avdelinger.php [R=301,L]
RewriteRule ^oppdrett\.html$ http ://www.example.com/avl_oppdrett/vis_oppdrett.php [R=301,L]
RewriteRule ^kattunger\.html$ http ://www.example.com/avl_oppdrett/vis_kull.php [R=301,L]
Please note the slight change for efficiency... NSR & nsr to only nsr with [NC] 'no case' directive added.
Justin
< If you rename all of your old-domain/pages.html to new-domain/index.html you quite possibly run the risk of creating duplicate content.
My understanding of a permanent redirect is that you are telling the search engines that the page in question no longer exists and has been replaced a new page - in this case your primary url.
As there is only one primary url, and this is reinforced by all of these now non-existant pages being redirected there, why would you risk creating duplicate content?
Where possible, best practice is to redirect to a page that provides the same information as the removed page.
If a similar page is not available, then a redirect to the index page for the removed page's subject area might be acceptable.
If no subject area index page is available, perhaps a site map is available.
And finally, if there is no replacement, then a custom 404/410 page with an explanation that the page has been removed, followed by a text link to the home page or site map, and perhaps a 20-second meta-refresh (also to the home page or site map) works fairly well.
Bottom line. If a direct or closely-related replacement page exists, then 301 to it. If no replacement page exists, then a 410-Gone response to HTTP/1.1 clients is correct, and a 404-Not Found response to HTTP/1.0 clients is correct.
Two factors to keep in mind: 1) Maintain usability and provide an "unsurprising" user-experience. 2) Use the HTTP protocol as intended to avoid problems with search engines.
Jim
None of these pages had referred any traffic in years, and I didn't even know they were still indexed until they started outranking important primary pages during Bourbon.
As these cobrands were tens of thousands of pages and not easily mapped to the corresponding page on the primary url, we decided to map EVERY page of each dead cobrand to the the primary domain's home page.
I guess it's a matter of picking your poison - trigger the dupe content filter by having identical cobrand pages, or potentially trigger a doorway filter by pointing thousands of pages at a single page.
We'll see how it goes.
(JD, I may take your advice on teh 410/404 solution. Thanks for that.)