I have a blog at:

http://charles-reace.com/kindleminds/

I just bought the kindleminds.net domain, and want to set up a permanent redirect to it for the old URL, so that links to "http://(www.)charles-reace.com/kindlminds/XXX" will go to "http://www.kindleminds.net/XXX". I think if I put the following in the .htaccess file in the root directory of my charles-reace.com domain it will do the trick, but I'd like a second pair of eyes to confirm or deny before I go live with it.

redirect 301 ^/kindleminds(/\.*)?$ http://www.kindleminds.net$1

    I think I need to make it work within this bit I already have?

    RewriteCond %{HTTP_HOST}   !^www\.charles-reace\.com [NC]
    RewriteCond %{HTTP_HOST}   !^$
    RewriteRule ^/(.*)         http://www.charles-reace.com/$1 [L,R=301]
    

      I ended up doing it by using PHP instead of Apache. :rolleyes:

      <?php
      if(stripos($_SERVER['HTTP_HOST'], 'reace'))
      {
         $url = $_SERVER['REQUEST_URI'];
         $url = preg_replace('#/kindleminds#i', '', $url);
         header("Location: http://www.kindleminds.net$url",TRUE,301);
         exit;
      }
      

        Crap, that's not working either. Hope there's an Apache rewrite expert along shortly.

          This is all you need, or at least what i've used a few times before. Maybe add in the new url part but it mite be best for google to rebuild it.

          <?php
          Header("HTTP/1.1 301 Moved Permanently"); 
          Header("Location: http://www.newdomain.com"); 
          

          UPDATE:

          This works,

          $url = $_SERVER['REQUEST_URI'];
          Header("HTTP/1.1 301 Moved Permanently"); 
          Header("Location: http://www.newdomain.com" . $url); 
          
            jerrylouise;10957055 wrote:

            This is all you need, or at least what i've used a few times before. Maybe add in the new url part but it mite be best for google to rebuild it.

            <?php
            Header("HTTP/1.1 301 Moved Permanently"); 
            Header("Location: http://www.newdomain.com"); 
            

            UPDATE:

            This works,

            $url = $_SERVER['REQUEST_URI'];
            Header("HTTP/1.1 301 Moved Permanently"); 
            Header("Location: http://www.newdomain.com" . $url); 
            

            Yeah, it works for the base url, but gets all screwed up when it points to a sub-dir, e.g. "charles-reace.com/kindleminds/about/". 🙁

              <?php
              $url = $_SERVER['REQUEST_URI']; 
              Header("HTTP/1.1 301 Moved Permanently"); 
              Header("Location: http://www.newdomain.com" . $url); 
              

              Seems to work fine for me regardless of how many sub directories there is.
              This is the .htaccess, since you don't need a directory structure now point everything to index.php on your old domain, this will redirect every request as is to the new domain.

              <IfModule mod_rewrite.c>
                  RewriteEngine On
                  RewriteRule ^(.*)$ index.php [PT,L]
              </IfModule>
              

                This is the .htaccess in the WordPress directory:

                
                # BEGIN WordPress
                <IfModule mod_rewrite.c>
                RewriteEngine On
                RewriteBase /
                RewriteCond &#37;{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule . /index.php [L]
                </IfModule>
                
                # END WordPress
                

                I guess this would be the best place to do a redirect if I'm at "charles-reace.com/kindleminds/" instead of "kindleminds.net/".

                  Aye change your .htaccess on your old site to look like my one provided above, it makes sure all requests regardless go to index.php(where you replace everything with the php code i provided) so will send the user to the new domain with the full url intact.

                    jerrylouise;10957059 wrote:

                    Aye change your .htaccess on your old site to look like my one provided above, it makes sure all requests regardless go to index.php(where you replace everything with the php code i provided) so will send the user to the new domain with the full url intact.

                    I'm going to take that and do some directory renaming and repointing, then see what I come up with....

                      Yes! Thanks, Jerrylouise. I ended up renaming the "kindleminds" directory to "km", then used the control panel to point the new domain to that directory instead of "kindleminds". Then I created an empty "kindleminds" directory and added index.php and .htaccess to it:

                      index.php:

                      <?php
                      $url = $_SERVER['REQUEST_URI'];
                      $url = preg_replace('#/?kindleminds#i', '', $url);
                      Header("HTTP/1.1 301 Moved Permanently");
                      Header("Location: http://www.kindleminds.net" . $url);
                      

                      .htaccess:

                      <IfModule mod_rewrite.c>
                          RewriteEngine On
                          RewriteRule ^(.*)$ index.php [PT,L]
                      </IfModule>
                      

                      Seems to be doing the trick. Now http://www.charles-reace.com/kindleminds/about takes you to http://www.kindleminds.net/about. 🙂

                        Your welcome, its nice to be the one giving answers for a change _

                          I'm confused... wouldn't something as simple as this:

                          RewriteRule ^(.*)$ http://www.kindleminds.net/$1 [R=301]

                          work in a .htaccess file placed within the "/kindleminds/" directory?

                            bradgrafelman;10957173 wrote:

                            I'm confused... wouldn't something as simple as this:

                            RewriteRule ^(.*)$ http://www.kindleminds.net/$1 [R=301]

                            work in a .htaccess file placed within the "/kindleminds/" directory?

                            Whenever I tried to do something like that, it seemed to conflict with other redirect stuff in the .htaccess file either in the root directory of my main site or in the actual directory of the blog (WordPress stuff), and either it would get ignored, or generate an error, or get to the right place but with a WordPress 404 page. For now, the solution I have works, and that's all that matters for me. 🙂

                              Write a Reply...