lbh2011 Posted May 19, 2011 Share Posted May 19, 2011 Hello Would anyone be able to help with this small problem... I have 2 domains, www.example.co.uk and www.example.com They are configured by my host to share the same webspace What I would like however, is to use .htaccess to redirect a visitor who accesses the site via www.example.com to be redirected to www.example.co.uk I somehow need to add this into my existing .htaccess code which redirects a non-www domain to a www domain for SEO purposes Does anyone know how this may work? In summary - 2 domains pointing to the same shared directory. The .com domain (both http://www.example.com and http://example.com) need to redirect to www.example.co.uk The .co.uk (http://example.co.uk) must also redirect to the www version (http://www.example.co.uk) The code I currently have is below (this redirects non-www to www): RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^example.co.uk [NC] RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301] Any suggestions welcome Quote Link to comment https://forums.phpfreaks.com/topic/236898-simple-htaccess-question/ Share on other sites More sharing options...
requinix Posted May 19, 2011 Share Posted May 19, 2011 Change ^example.co.uk (which only continues if the hostname is "example.co.uk") to !^www.example.co.uk (which continues if the hostname is not "www.example.co.uk"). Quote Link to comment https://forums.phpfreaks.com/topic/236898-simple-htaccess-question/#findComment-1217778 Share on other sites More sharing options...
lbh2011 Posted May 19, 2011 Author Share Posted May 19, 2011 Thanks requinix - that works perfectly Quote Link to comment https://forums.phpfreaks.com/topic/236898-simple-htaccess-question/#findComment-1217786 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.