Forum Moderators: phranque
From: www.olddomain.ca
To: www.newdomain.ca
I have been struggling for several hours to get the .htaccess file to correctly handle all the cases that we need to deal with to properly redirect the traffic from the old domain to the new domain.
Here is some background:
1. most of the pages in both sites are generated with syntax such as this... www.olddomain.ca/index.php?page=pagename
2. Google has indexed about 60 pages from the old site. About 30 of these pages have the exact same syntax in the new site, except the domain name is different. E.g. www.olddomain.ca/index.php?page=pagename1 becomes www.newdomain.ca/index.php?page=pagename1
3. About 30 of the previously indexed pages are now obsolete. These obsolete pages are easily identified because they all contain the unique string "keep_layout=pda". This came about because the old site was modified for PDA usage at one point and the new site does not have this requirement.
Here is a sample of a valid page from the old domain that is now obsolete:
www.olddomain.ca/index.php?page=faqs&keep_layout=pda&keep_device=pda
The Goal
========
The simple goal is to accomplish the following:
1. For all visits to www.olddomain.ca where the page is now obsolete, redirect the visitor to the Home Page of the new domain.
2. For all visits to www.olddomain.ca where the url is identical in both the old site and the new site, redirect the visitor to the exact same url with the only difference being the replacement of olddomain.ca with newdomain.ca
My Struggles
============
I am somewhat familiar with creating an .htaccess file... The first 2 lines in my .htaccess file are:
Options +FollowSymLinks
RewriteEngine on
My original RewriteRule looked like this:
RewriteRule ^.*$ [newdomain.ca...] [R=301,L]
Question: For some reason when I had the rule this way, the "index.php?" portion of the url was being dropped in the new url. Can someone please explain why this happens?
To overcome this problem, I modified the rule to the following:
RewriteRule ^.*$ [newdomain.ca...] [R=301,L]
This seems to work for the cases where the page in the olddomain and newdomain are identical. However for the obsolete pages I am getting redirected to an error page.
For the cases where the page is now obsolete, I have been struggling to get the correct rule. In fact, I am not sure if I need to use RewriteCond in addition to RewriteRule to cover this case.
For example, I have tried placing the following rule BEFORE the other rule, but it does not work...
RewriteRule "layout" [newdomain.ca...] [R=301,L]
Recall that I am trying to redirect any URL containing the phrase "layout" to the Home Page of the new domain.
I would appreciate any help that can be provided.
Regards,
Jim
RewriteCond %{QUERY_STRING} &?keep_layout=pda&?
RewriteRule ^index\.php$ http://www.newdomain.ca/? [R=301,L]
#
RewriteRule (.*) http://www.newdomain.ca/$1 [R=301,L]
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim