Announcement

Collapse
No announcement yet.

301 redirects huge htaccess file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    301 redirects huge htaccess file

    Is there a way to dynamicly lookup old urls and redirect to a new url using php and MySQL.

    Here is the problem:
    With the advice of an seo specialist. my client has changed the short link style used in MM4 to a new format.

    domain.com/product_OR_categorycode.html has become
    domain.com/productcode_categorycode.html

    In most cases the category codes have change to something more seo friendly and many of the product codes have also changed as well.

    To make this work they did 301 redirects in the htaccess file... 25000 times.

    Since htaccess gets parced for each server request (including pages, images, css and javascript files) Thir site has take a very visible performance hit.

    It would seem their must be a way to do dynamicly lookup the old code(s) and redirect to a new url using php and MySQL.

    Any Ideas?
    Ray Yates
    "If I have seen further, it is by standing on the shoulders of giants."
    --- Sir Isaac Newton

    #2
    Re: 301 redirects huge htaccess file

    Do you mean the old link looked like...

    domain.com/product.html

    OR

    domain.com/categorycode.html

    Or that the actual word "OR" was in the url?

    Is the product the same thing as productcode?

    Comment


      #3
      Re: 301 redirects huge htaccess file

      domain.com/productcode.html

      OR

      domain.com/categorycode.html

      They hade a module that would differentiate between the two and redirect to the correct page.

      I should say they moved from MM4 toMM5.5
      Last edited by RayYates; 11-25-08, 06:53 AM.
      Ray Yates
      "If I have seen further, it is by standing on the shoulders of giants."
      --- Sir Isaac Newton

      Comment


        #4
        Re: 301 redirects huge htaccess file

        since the rewrites are in the root, it might be very hard to make rules. You can try using rewrites using
        Code:
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        to check if the file exists. It really depends what the URL was and what it becomes. If there's a pattern, you can combine the rules.

        If there isn't a pattern, what I have done in the past is used a template to create static html files that redirect to the new page. Creating 25000 files might suck, so if you're bored you can create a PHP script to generate (write to) the needed files?

        Here's the template I use:
        Code:
        <?php
        	header("HTTP/1.0 301 Moved Permanently");
        	header("Location: http://www.mydomain.com/path_to_file.html");

        Comment


          #5
          Re: 301 redirects huge htaccess file

          Naturally the Big G doesn't like HTML redirects. They prefer 301s.

          I have the same problem doing an upgrade from old SEO to new SEO.
          Steve Strickland
          972-227-2065

          Comment


            #6
            Re: 301 redirects huge htaccess file

            Dave @ hostasaurus pointed me to

            http://httpd.apache.org/docs/2.2/mod...tml#rewritemap

            Untested. I think I can do this in htaccess

            RewriteMap map301 prg:remap.mvc
            RewriteRule ^/(.*).html$ {map301:$1}

            Now I just have to write remap.mvc
            Ray Yates
            "If I have seen further, it is by standing on the shoulders of giants."
            --- Sir Isaac Newton

            Comment


              #7
              Re: 301 redirects huge htaccess file

              Originally posted by Biffy View Post
              Naturally the Big G doesn't like HTML redirects. They prefer 301s.

              I have the same problem doing an upgrade from old SEO to new SEO.
              I think you're referring to meta redirects. A PHP redirect like I showed would pass proper headers (very similar to what Apache would do). Even if not, Big G will have to just deal with it -- there's no way I'd do 25000 redirect rules just to keep them happy.

              Is RewriteMap going to be any more efficient? It is still going to be processed on every request, right? I always thought it was just there for ease of upkeep.

              Comment


                #8
                Re: 301 redirects huge htaccess file

                I was thinking of putting the records in a MYSQL table old, new with an index on the old code. Then the mvc program would just lookup the old code and return the new url.

                I think we can do this in apache config so that it only does this lookup on .html files and not on every server request.
                Ray Yates
                "If I have seen further, it is by standing on the shoulders of giants."
                --- Sir Isaac Newton

                Comment


                  #9
                  Re: 301 redirects huge htaccess file

                  Well, strickly speaking...that huge redirect file would only need to be in place for a short while...until all the search engines redirect the links based on it. With Google, you should be able to submit a sitemap.xml file (using the OLD links) and once that is accepted, Google should only be listing the new urls (could be tested with an INURL search).
                  Bruce Golub
                  Phosphor Media - "Your Success is our Business"

                  Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                  phosphormedia.com

                  Comment


                    #10
                    Re: 301 redirects huge htaccess file

                    Originally posted by Brandon MUS View Post
                    I think you're referring to meta redirects. A PHP redirect like I showed would pass proper headers (very similar to what Apache would do).

                    Is RewriteMap going to be any more efficient? It is still going to be processed on every request, right? I always thought it was just there for ease of upkeep.
                    Correct on the php, that is precisely the same thing apache sends back.

                    RewriteMap is very efficient because it's loaded into memory as part of the server config rather than in .htaccess, and it's just a few statements rather than 25,000.
                    David Hubbard
                    CIO
                    Miva
                    [email protected]
                    http://www.miva.com

                    Comment


                      #11
                      Re: 301 redirects huge htaccess file

                      Good to know, thanks David.

                      Comment

                      Working...
                      X