Forum Moderators: phranque
RewriteEngine On
RewriteRule . [newdomain.com%{REQUEST_URI}...] [R=301,L]
but it doesn't work properly. it says the page isn't redirecting properly.
If the user types in www.olddomain.com/subdir/file.php then I want it to redirect to www.newdomain.com/subdir/file.php. I want that to happen for every olddomain request.
Any ideas?
First, check %{HTTP_HOST} to make sure there is a non-blank Host: header in the client HTTP request. Then, if present, check that Host header to be sure you have not already redirected to "www.newdomain.com". If the Host header is non-blank, and indicates a request for a domain other than "www.newdomain.com", then do the redirect.
RewriteEngine on
#
# if non-blank host header
RewriteCond %{HTTP_HOST} .
# and requested domain is NOT www.newdomain.com
RewriteCond %{HTTP_HOST} [b]![/b]^www\.newdomain\.com
# redirect to requested page on www.newdoamin.com
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
Jim
[newdomain.com...]
instead of just [newdomain.com...]
How can I fix this?
Basically, if another bit of code internally rewrites requests for, say, newdomain.example.com, to example.com/newdomain, and THEN you execute the new redirect code, then the redirect will 'expose' the internally-rewritten URL as you have experienced.
It is necessary to do the domain canonicalization redirects first, before doing your internal rewrites.
This is likely the result of the way your "addon" was created -- I can't speak to that, as there are various hosting company and "control panel" methods -- all different, some correct, and a few that are easy to work with... :)
Jim