Forum Moderators: phranque
During testing I came across problems I'd never seen before,
The site has a members section and when logging in at 'www.newdomain.co.uk' the page refreshed to show the URL 'newdomain.co.uk' which caused script problems. After a lot of hair tugging I found the answer on this forum thank you.
I now have a .htaccess as below and it works just great.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^newdomain\.co\.uk
RewriteRule (.*) [newdomain\.co\.uk...] [R=301,L]
Now when I move my old domain over to point at the same webspace as the new domain I envisage a similar problem.
What I would like to happen is which ever URL visitors come to [either www.newdomain.co.uk or www.olddomain.co.uk] I want them to be re-directed to www.olddomain.co.uk transparently if possible.
So would this work
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain\.co\.uk
RewriteCond %{HTTP_HOST} ^newdomain\.co\.uk
RewriteCond %{HTTP_HOST} www\.newdomain\.co\.uk
RewriteRule (.*) [olddomain\.co\.uk...] [R=301,L]
One last thing should the dot in [olddomain...] be escaped as in Rewrite condition 3
Any help would be greatly appreciated thank you.
Steve
2) I'd stick a '$' at the end of each hostname in the RewriteCond, like this:
RewriteCond %{HTTP_HOST} ^www\.newdomain\.co\.uk$ [OR]
3) make sure to prefix the hostname in your third RewriteCond with a ^
4) Literal '.' characters SHOULD be escaped in RewriteCond lines, since you're performing string matches. Literal '.' characters SHOULD be escaped on the *left* side (LHS) of RewriteRule lines. Literal '.' characters SHOULD NOT be escaped on the *right* side (RHS) of the RewriteRule lines, since that's simply a string which will be sent back to the browser (after variable expansion). Note that using them, in the incomplete test I ran, doesn't appear to hurt anything, but they're not needed*.
*I'd have to do some serious playing; it's *possible* that in certain exceptional circumstances escaping the literal '.' character would be required, but 99.99+% of the time (read: now), it's not. =)
2) I'd stick a '$' at the end of each hostname in the RewriteCond, like this:RewriteCond %{HTTP_HOST} ^www\.newdomain\.co\.uk$ [OR]
I do not recommend end-anchoring hostname patterns. My reason is that it is valid to append a port number to the domain, and some browsers (such as Mozilla) will put that into the Host header. So, using the above example pattern, the server will see %{HTTP_HOST} as "www.newdomain.co.uk:80" and the RewriteCond will unexpectedly fail.
The other alternative is to use an end-anchor, but explicitly allow for appended port numbers, for example:
RewriteCond %{HTTP_HOST} ^www\.newdomain\.co\.uk(:[0-9]{1,5})?$ [OR]
Jim
It's only now I can see how much control I can have over how the site works, looks like I've a lot of reading to catch up on.
Thanks again Steve.