Forum Moderators: phranque
I earlier used a [subdomain.olddomain.com...] as my website and [subdomain.olddomain.com...] for my blog address.
Now recently I've moved to [newdomain.com...] which is entirely for me. I've set up the blog at [subdomain.newdomain.com...]
Now the issue is, while I can redirect from [subdomain.olddomain.com...] to [newdomain.com...] which works and forwards the trailing uri's properly, when I try to forward [subdomain.olddomain.com...] to the [subdomain.newdomain.com...] it actually goes to
[subdomain.newdomain.com...]
For the parent folder which maps to [subdomain.olddomain.com,...] the .htaccess reads:
RewriteEngine onRewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^newDomain\.com
RewriteRule (.*) http://www.newdomain.com/$1 [R=301]
and for the blog folder which maps to [subdomain.olddomain.com...] the .htaccess reads:
RewriteEngine On
RewriteCond %{HTTP_HOST}!^subdomain\.olddomain\.com [NC]
RewriteRule .* http://subdomain.olddomain.com%{REQUEST_URI} [R=301,L]RewriteCond %{HTTP_HOST}!^subdomain\.newdomain\.com
RewriteRule (.*)$ http://subdomain.newdomain.com/$1 [R=301,L]
But this is not working correctly.. If I type [subdomain.olddomain.com...] (Note the trailing slash) it works fine and keeps the trailing URI intact and hence goes to [subdomain.newdomain.com...]
But if I enter [subdomain.olddomain.com...] (No trailing slash) it goes to [subdomain.newdomains.com...] where the part in quotes is the folder path from the old server..
Can someone help me clean this up?
Thanks a lot.
Apache sees the missing trailing slash, invokes mod_dir, and then uses the ServerName to build the new URL (see the Apache docs for details).
If you don't have httpd.conf access, the simplest solution would be to add a rule to detect missing trailing slashes, so that this does not happen. for example:
# Add trailing slash if missing (skip rewrite for paths with a
# period in the last part, already ending in slash, or blank)
RewriteCond %{REQUEST_URI} !(\.[^/]+¦/)$
RewriteRule (.+) /$1/
Replace the broken pipe "¦" character above with a solid pipe before use; Posting on this baord modifies the pipe character.
Jim