htaccess for moving domain names
Apache uses .htaccess files as a way to make configuration changes on a per-directory (and subdirectories) basis. They are a powerful tool when it comes to moving folders of changed files or in my case domain name rewriting.
Currently I am using a short domain name (prsos.co.uk) as a redirect to a specific page on the full domain name petrescuesos.co.uk. In the past I've even used ColdFusion to do by putting something along the lines in my Application.cfm.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfif findNoCase('prsos', cgi.server_name)>
<cfheader statustext="Moved permanently" statuscode="301" />
<cfheader value="http://www.petrescuesos.co.uk" name="Location">
</cfif>
1<cfif findNoCase('prsos', cgi.server_name)>
2<cfheader statustext="Moved permanently" statuscode="301" />
3<cfheader value="http://www.petrescuesos.co.uk" name="Location">
4</cfif>
This still gives the browser/spider the correct http header but why waste cpu styles on even doing this when the web-server can handle it natively. Below is the Apache .htaccess I've just put in place.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
#Turn rewrite on
RewriteEngine on
#Look at the HTTP_HOST and regex search for old domain name
rewritecond %{http_host} ^(.*)prsos.co.uk [nc]
# The rule. Change the http_host to the new domain location. NC means NoCase
rewriterule ^(.*)$ http://www.petrescuesos.co.uk/index.cfm?action=pets.found [r=301,nc]
1#Turn rewrite on
2RewriteEngine on
3#Look at the HTTP_HOST and regex search for old domain name
4rewritecond %{http_host} ^(.*)prsos.co.uk [nc]
5# The rule. Change the http_host to the new domain location. NC means NoCase
6rewriterule ^(.*)$ http://www.petrescuesos.co.uk/index.cfm?action=pets.found [r=301,nc]