Welcome to WebmasterWorld Guest from 22.214.171.124
I've been going over the extensive information on WebMasterWorld regarding mod_rewrite, but I'm still puzzled as to the best way to go about the following.
The scenario is this.
My client has decided that they want to change the name of the site, so a new domain name will be chosen. This php based site contains dynamic URL's generated through a custom CMS + a phpBB forum. It's a fairly large site, so setting up 301 redirection on a URL by URL basis isn't an option. Everything else will remain the same in relation to file base structure, IP etc. etc. etc., only the domain name will be changed.
What would be the best way to go about this so that current search engine listings are not made invalid, visitors wind up on the right page and SE spiders won't balk at the new domain name. Is mod_rewrite the best way to go and what would be the syntax?
I greatly appreciate your feedback and apologise if this info is already available as plain as day on WebmasterWorld - the more I read, the more I confused myself :0).
Point the new domain to the existing server with a new DNS entry. Then add the following lines to .htaccess in the root directory of the Web site:
RewriteRule ^(.*)$ [newdomain.com...] [R=permanent,L]
This reads "If the hostname in the requested URL is not [newdomain.com,...] rewrite the URL using [newdomain.com...] as the hostname, attach the requested URI, and return the resulting new URL, along with a 301-Moved Permanently server response code to the requestor. This is the Last RewriteRule to be processed for this request."
A browser will then re-request the desired page using this updated URL, as supplied by your server.
The above will rewrite all requests for [oldomain.com...] to [newdomain.com....] It will also rewrite [oldmain.com...] and [newdomain.com...] to [newdomain.com....] You can change the behaviour with respect to "www" as desired, by including or excluding the "www\." in the RewriteCond and the "www." in the RewriteRule.
The above can also be used in the httpd.conf configuration file with minor adjustments. Query strings will be preserved. More info [httpd.apache.org].
That's about it - it's not very difficult to do, but I suggest you test it on a production server or at least during the time of least site traffic!
Search engines will see the 301-Moved Permanently response returned by the server, and update their database to show the new URL in their search results. Anyone using a browser to access the site will see the URL in their address bar update to the new URL as well. You will need to "manually" ask that your listings in ODP, Yahoo, and other human-edited directories be updated.
[edited by: jdMorgan at 7:40 am (utc) on Oct. 30, 2002]