Forum Moderators: phranque

Message Too Old, No Replies

New server, apache 301 redirect

Moving my blog to a subdomain

         

plasticgoat

2:32 pm on Mar 22, 2012 (gmt 0)

10+ Year Member



Hello,

I am moving my websites to a new host (Debian-Apache-MySql-Php). I have a new IP address, but I think it doesn't matter, and I'm also moving my blog to a subdomain (www.mydomain.com to blog.mydomain.com).

My new blog is up and running, so I "just" need to redirect my old blog pages to the new one.
I have read quite lot of articles, on redirection in general (like [seomoz.org...] and some specific about wordpress.

The thing is that on my old blog is set up like that (WordPress General settings):
Home : http://www.mydomain.com
SiteUrl : http://www.mydomain.com/wordpress

Apache is configured with
http://www.mydomain.com
on /home/www. The
http://www.mydomain.com/wordpress
is just a wordpress settings, that seems to cause me trouble for redirecting
I also have a sub-domain
http://sub.mydomain.com
on /home/www/sub, and an other domain
http://www.domain2.com
on /home/www/domain2.
I don’t want to redirect them yet.

So, on my server for my blog
I have a index.php and a .htaccess under /home/www
and also a index.php and a .htaccess under /home/www/wordpress.

I first tried to put the redirection in the top .htaccess :
- RedirectMatch 301 /(.*) http://blog.mydomain.com/$1
: it redirects everything including my other sites, so this is not the solution.
- RedirectMatch 301 /wordpress/(.*) http://blog.mydomain.com/$1
: it partially works some links like "Home" are not redirected
- Redirect 301 /2009/02/allo/ http://blog.mydomain.com/2009/02/allo/

It works but if I put too many redirect (one for each post) in the .htaccess, I get a server error 500

Then I tried to put the redirection in ./home/www/wordpress/.htaccess :
- RedirectMatch 301 /(.*) http://blog.mydomain.com/$1
: it failed also (but honestly I don't remember why, I've done too many try :P )

That’s a long explanation, but I hope it will help you to help me :)

My first question is where should I put my redirect directives (/home/www or /home/www/wordpress) ?
My second question is, shouldn’t I use RewriteCond / RewriteRule instead of RedirectMatch ?

Any help will be appreciated :)
Thanks.

lucy24

7:39 pm on Mar 22, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Second question: YES. This will allow you to set up Conditions looking at the host: primary domain, subdomain or other.

First question: All redirects-- no matter what module handles them-- have to go where the affected requests can "see" them. Generally that means your top-level domain directory, assuming the subdomain is physically located in a directory within that directory.

g1smd

8:39 pm on Mar 22, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use a RewriteRule for this, not RedirectMatch. Configure it as a 301 redirect.

You can then add a preceding RewriteCond looking at HTTP_HOST if you really have to.

plasticgoat

9:38 pm on Mar 22, 2012 (gmt 0)

10+ Year Member



Thanks for your replies !

I finally have added the directive in my apache virtualhost configuration :

<IfModule mod_rewrite.c>
RewriteEngine On

# use RewriteLog to debug problems with your rewrite rules
# disable it after you found the error our your harddisk will be filled *very fast*
# RewriteLog "/var/log/apache2/rewrite_log"
# RewriteLogLevel 2

# Rewrite with redirect moved permanently
RewriteCond %{HTTP_HOST} ^www\.jnicolas\.name$
RewriteRule ^/(.*) http://blog-quebec.jnicolas.name/$1 [R=301,L]
</IfModule>


Now I would like to prevent the redirection to occur when accessing the old admin page.
I tried to add another RewriteCond, but it doesn't work :
RewriteCond %{REQUEST_URI} !.*wp-admin.*


Any idea why ?

g1smd

9:59 pm on Mar 22, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Both of the .* patterns are not needed.

!wp-admin would suffice

You added this RewriteCond where in the file? It belongs just before the rule it applies to.

plasticgoat

11:11 pm on Mar 22, 2012 (gmt 0)

10+ Year Member



Yes I have added the new condition just before the rule :)

I find out that all the posts URL are like this :
http://www.mydomain/year/month/post_title

whereas all the URL for wordpress backend are like this :
http://www.mydomain/wordpress/#*$!x
and '#*$!x' could be wp-admin, wp-login ...

I want to keep the backend available in the old domain and redirect everything else, so I finally used that new condition instead :
RewriteCond %{REQUEST_URI} !/wordpress/


I guess it's because my condition was checking the end of the URI instead of the first URI part avec domain name ("wordpress"), that it wasn't working.

Should I have used RedirectBase to be able to use wp-admin in my RewriteCond ?