WordPress – htaccess rewrite all URLs (inc image hrefs) from one domain to another

.htaccess301-redirectrewriteWordpress

I've got a wordpress blog on a subdirectory which I've recently migrated from a .com to a .co.uk (myurlstudio.com/blog to myurl.co.uk/blog). The problem is that many of the posts have images in them, and their hrefs still point to the old domain, and so they don't work with the current htaccess settings. The images point to http://www.myurlstudio.com/blog/wp-content/uploads/image.jpg, when I want them to point to http://www.myurl.co.uk/blog/wp-content/uploads/image.jpg. So the thing I need to change in htaccess is 'http://www.myurlstudio.com/blog' to 'http://www.myurl.co.uk/blog' wherever it comes up.

Current htaccess looks like this (it's the standard URL-rewriting scheme for concrete5):

# -- concrete5 urls start --
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www.)?myurlstudio.com$
RewriteRule ^(.*)$ http://www.myurl.co.uk/$1 [L]


RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]


</IfModule>
# -- concrete5 urls end --

As you can see myurlstudio.com is redirected, but URLs inside documents don't seem to be rewritten.

Any help would be much appreciated!

Best Answer

If you have access to the old host (sounds like you do from the comments), your rule should work when placed in the docroot of the old site:

RewriteCond %{HTTP_HOST} ^(www.)?myurlstudio.com$
RewriteRule ^(.*)$ http://www.myurl.co.uk/$1 [L,R=301,QSA]

BUT that only redirects old requests. You still need to update the site to reference the new domain if the old domain is to expire eventually.

Related Topic