0

I need a little help with my .htaccess before I deploy it!

I want to 301 redirect almost everything from elementalthreads.com to ethreads.com, excluding blog/wp-content/uploads, and /pommo.

Am I doing this right?:

RewriteEngine on
#exclude old uploads folder and /pommo
RewriteCond %{REQUEST_URI} !^/(blog/wp-content/uploads|pommo) [NC]
RewriteRule (.*) http://ethreads.com/$1 [R=301,L]

Will that transfer canonical pagerank?

Here's where I know I need help:

  1. The old site has a wordpress blog, which I've cloned on the new domain. I'd love to preserve the permalinks, which are almost 1:1, eg: http://www.elementalthreads.com/blog/ethreads-now-on-amazon-com/ redirects to
    http://ethreads.com/ethreads-now-on-amazon-com/ (note /blog/ is missing here)

  2. And the blog index http://www.elementalthreads.com/blog/ should redirect to http://ethreads.com/blog/, which seems like an exception to the above rule, since "/blog/" should only be preserved here?

I'm stumped about how to regEx or otherwise define these last two conditions/rules. Any help would be most appreciated!

1 Answer 1

1

That looks correct to me. However, you should not put this live without checking it, there really is nothing preventing you from being able to test it. One thing to bare in mind is that browsers can cache 301 response codes so when testing you should use [R,L] as your flags. Once you are happy add the [R=301,L] back in before deployment.

OK for points (1) & (2)

# only redirect the blog direcotry
RewriteRule ^blog/?$            http://ethreads.com/blog/ [NC,R=301,L]

# redirect all sub folders of blog to the new domain
RewriteRule ^blog/([\w-])/?$    http://ethreads.com/$1/ [NC,R=301,L]
4
  • Thanks! That's very helpful regarding the caching. I was wondering about the "permanent" nature of 301. Do you have any tips about how to add the 2 additional rules/conditions for the /blog & permalinks in #'s 1 & 2 above?
    – case2000
    Mar 25, 2012 at 18:01
  • THANK YOU! This is working great. I added one more rule to handle wordpress categories and tags 'RewriteRule ^blog/([^/]+)/([^/]+)/?$ ethreads.com/$1/$2 [NC,R,L]'. For some reason I was unable to use your pattern of '([\w-])' in this context. Can you explain what '\w-' means? I understand '([^/]+)' fine, but am having a hard time googling how your pattern works. Thanks again!
    – case2000
    Mar 26, 2012 at 18:45
  • \w means any letter or number or the underscore character. So [\w-] means any letter, number, underscore or hyphen. Make sense?
    – baynezy
    Mar 26, 2012 at 19:56
  • Yes - it does. I figured it was something like that. Thank you very much for your help! Yay stackoverflow!
    – case2000
    Mar 26, 2012 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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