Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've moved my WordPress installation from one domain to another, and I want to use an .htaccess file on the original to redirect visitors to the new page on the new website.

The old site is http://www.steve.doig.com.au/wordpress/.

The new site is http://www.superlogical.net

I tried using tried using the following .htaccess file in the /wordpress directory:

RedirectMatch 301 http://www.steve.doig.com.au/wordpress(.*) http://www.superlogical.net/$1

However, all this does is redirect visitors to the URL: http://www.superlogical.net/wordpress/

I guess this is working properly, but I don't have Wordpress installed in a /wordpress folder on the new domain. How do I remove this from the URL redirected to?

share|improve this question
    
The RedirectMatch directive matches against a root-relative (starting with a slash) URL-path, not the absolute URL, so the above directive would not have done anything - it would not have matched. Even it did match, it wouldn't have redirected to the /wordpress folder - so there must have been something else going on here. Incidentally, 301 redirects are cached by the browser, so it's quite possible you were seeing a cached response. It's often best to first test with 302 (temporary) redirects for this reason. – w3dk Dec 15 '15 at 15:24
up vote 2 down vote accepted

In the /wordpress/.htaccess file, I changed it to the following:

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.*)$ http://www.superlogical.net/$1 [R=301,L]

Which resolved it for me.

share|improve this answer
    
I have some concern that by this able to redirect 301 to old domain to new domain but what about to redirect pages ...? – user14966 Apr 26 '12 at 10:02

I've been told by my webhost to try the following:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?steve\.doig\.com\.au/wordpress/$ [NC]
RewriteRule ^(.*)$ http://www.superlogical.net/$1 [R=301,L]

But this only works for the /wordpress folder, and not for any post or category page.

share|improve this answer
    
This shouldn't have worked at all. The /wordpress/ URL-path is not part of the HTTP_HOST variable, so the condition would have failed, preventing the redirect? – w3dk Dec 10 '15 at 14:59

As you’re using regexp on the second parameter you want to escape the dots. Change

http://www.steve.doig.com.au/wordpress(.*)

to

http://www\.steve\.doig\.com\.au/wordpress(.*)

The logic itself, how you meant it, should work though. Passing the following URL-part to the new URL.

share|improve this answer
    
Thanks. It successfully redirects from the /wordpress folder of the old website, but I receive a page not found error when I try to load the URL of an individual wordpress post on the old site. The browser still has the old URL in the address bar, indicating it has not tried to redirect the page. Do I need to include an .htaccess file in every content folder? – Steve Mar 2 '11 at 4:26
    
.htaccess files will apply to the directory it is in as well as all sub-directories. See httpd.apache.org/docs/2.2/howto/htaccess.html#what – Kissaki Mar 5 '11 at 3:33
    
Thanks, I thought so, but this doesn't change the fact it doesn't work for me. – Steve Mar 7 '11 at 2:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.