cancel
Showing results for 
Search instead for 
Did you mean: 

htaccess for 301 from .co.uk to .com not working

ketter
Dabbler
Posts: 16
Registered: ‎24-01-2008

htaccess for 301 from .co.uk to .com not working

Hi all
I am having some problems with a htaccess used to redirect .co.uk to .com
Both .co.uk and .com are pointed via dns at the same folder in the ccgi server.  I am using this following script:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^www.domain.co.uk [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
But what is happening is that http://www.domain.co.uk/ is returning HTTP 200 OK
but the stylesheet and images are correctly being returned with a 301,
which then returns the new .com correctly as a HTTP 200 OK
So in the url address bar has the .co.uk, with associated file being served from the .com
Not ideal
Does anyone have an idea why this is not working correctly?
Ta
John
2 REPLIES 2
zubel
Community Veteran
Posts: 3,789
Thanks: 1
Registered: ‎08-06-2007

Re: htaccess for 301 from .co.uk to .com not working

Hmm,

Options +FollowSymLinks
RewriteEngine on
rewritecond %{HTTP_HOST} ^www\.domain\.co\.uk [NC]
rewritecond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ http://www.domain.com/$1?%1 [R=301,L]

That should do it - it will rewrite the query string too, if your site uses them.
B.
ketter
Dabbler
Posts: 16
Registered: ‎24-01-2008

Re: htaccess for 301 from .co.uk to .com not working


I have changed and uploaded the htaccess file, but the redirect is not working for php files. 
Css, and images are being redirected correctly.
Is there anything I can do to get it working on the php files?