Forum Moderators: coopster
File 1
DirectoryIndex redirectall.php
ErrorDocument 404 /redirectall.php
File 2
<?php
# redirect everything from site1 to www.site2.co.uk
$req=$_SERVER['REQUEST_URI'];
$correcturl="http://www.site2".strtolower($req);
#die($correcturl);
#header("Location: $correcturl",true,301);
header("HTTP/1.1 301 Moved Permanently");
header("Location: $correcturl");
?>
redirectall.php
$correcturl="http://www.site2".strtolower($req);
.co.uk is missing from your example code. ErrorDocument directive only files which don't exist on the old site will generate a redirect. If you haven't deleted all the files the redirect will not happen. Are you sure that the redirect is being correctly generated, and that there's no 404 header in there? Use the Live HTTP Headers extension for Firefox to check it out. RewriteCond %{REQUEST_URI} !redirect\.php
RewriteRule .* /redirect.php [L] RewriteCond %{HTTP_HOST} !(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L] RewriteRule [A-Z] /redirect.php [L] RewriteCond %{HTTP_HOST} !(www\.example\.com)?$
RewriteCond %{REQUEST_URI} !redirect\.php
RewriteRule (.*) http://www.example.com/$1 [R=301,L] <?php
# redirect everything from example.com to www.example.co.uk
$req=$_SERVER['REQUEST_URI'];
$correcturl="http://www.example.co.uk".strtolower($req);
#die($correcturl);
#header("Location: $correcturl",true,301);
header("HTTP/1.1 301 Moved Permanently");
header("Location: $correcturl");
?>
RewriteCond pattern. html|htm can be simplified to html? making the 'l' optional. RewriteCond should be as per the previous post ustilising ! and ( )? and www, and not just ^example\.com RewriteRule to make the code easier to read. RewriteCond %{REQUEST_URI} !redirect\.php
# Redirect mixed-case requests for any domain to new domain via redirect script
RewriteRule [A-Z] /redirect.php [L]
# Redirect all other requests for any non-canonical domain to new domain
RewriteCond %{HTTP_HOST} !(www\.example\.com)?$
RewriteCond %{REQUEST_URI} !redirect\.php
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !redirect\.php code is VITAL. It stops an external redirect to the script path happening for previously internally rewritten requests. RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ RewriteMap lc int:tolower
RewriteRule . http://www.newdomain.com${lc:%{REQUEST_URI}} [R=301,NE,L]
.htaccess file in the old site's document root or the site's VirtualHost block (or the main server config).