Announcement

Collapse
No announcement yet.

301 redirects or work-arounds?

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

    301 redirects or work-arounds?

    Hi folks --

    One of my clients has asked if the store can do 301 redirects for discontinued products and categories. I've been doing a little reading, and it looks to me like Miva Script can't do a 301, because that requires modifying the status code that the server sends back to the browser. Is that correct?

    In that case, I'm looking for other solutions. For shoppers using old URLs, it's easy enough to keep a table of old product codes, and then display the corresponding new product by having a system-ex module that alters the value of g.Screen. But that's no help with the search engines. For them, I can put canonical links on the pages; would that work as well as a 301?

    Also, there's the possibility of redirecting the browser with a meta-tag instead of a 301. But I wonder what the search engines would make of that?

    Any recommendations? Thanks --
    Kent Multer
    Magic Metal Productions
    http://TheMagicM.com
    * Web developer/designer
    * E-commerce and Miva
    * Author, The Official Miva Web Scripting Book -- available on-line:
    http://www.amazon.com/exec/obidos/IS...icmetalproducA

    #2
    Re: 301 redirects or work-arounds?

    You can change the HTTP status code in MivaScript by using miva_output_header() to output a "Status" header. In stock Miva Merchant the HTTP Headers component uses this mechanism to output a 404 response code for the NTFD page.

    Comment


      #3
      Re: 301 redirects or work-arounds?

      Great, I think that tells me what I need. I see that the http-headers component is included in the LSK, too; that answers some other questions. Thanks, Burch!
      Kent Multer
      Magic Metal Productions
      http://TheMagicM.com
      * Web developer/designer
      * E-commerce and Miva
      * Author, The Official Miva Web Scripting Book -- available on-line:
      http://www.amazon.com/exec/obidos/IS...icmetalproducA

      Comment


        #4
        Re: 301 redirects or work-arounds?

        if they're on apache you could use the .htaccess file instead, something like

        redirect 301 /oldURL.htm http://www.example.com/newURL.htm
        Looking for work as of March 2024! I've been a web developer for going on 20 years, with most of that time spent on Miva sites.

        Comment


          #5
          Re: 301 redirects or work-arounds?

          Originally posted by Mike521w View Post
          if they're on apache you could use the .htaccess file instead, something like

          redirect 301 /oldURL.htm http://www.example.com/newURL.htm

          I used to be a major proponent of using the .htaccess for everything.

          Got a redirect? .htccess
          Need password protected content? .htaccess
          Broken faucet? .htaccess

          But, the .htaccess is processed on every server request. Images, XHR, yadda yadda yadda. It's a very powerful tool to use, but be careful overloading it, because it can really slow down the processing (depending on what you're doing with it).

          What I do now is use a SMT language enhancing module (Toolbelt or Tool Kit) to handle the redirects. This puts the burden of detection on Miva Merchant, not the server. And those redirects are only taken into consideration on specific pages. That way I won't have to manually update the .htaccess file when products are in stock and out of stock.

          At one time I wrote some "fuzzy logic" for the NTFD page. I'd look at the parameters given in the query string (screen=prod&product_code=foo, screen=ctgy&category_code=bar), do some quick analysis on them and see what might match up.

          So, the more complex the logic got, the more accurate the results would be. For instance, it would check for misspellings, and offer suggestions, if it was requesting a product that didn't exist anymore, it would offer products which had similar product codes. If it was neither, then it would show best seller lists. But the http response code which was returned, was important for SEO reasons. If it was redirecting to a product, then it would issue a 301 (permanent new location), and if it was a suggestion type of page, it might be a 302 (temporary redirect). The other things involved in the logic would be to email someone to alert them of the issue so they could see what the issue was (contacting the person with the referral link, correcting the page on site which has the typo, etc.)

          Here's an example on the NFTD page:
          Code:
          <mvt:if expr="'|' $ g.screen $ '|' CIN '|prod|'">
              <mvt:comment> Query DB for an appropriate product </mvt:comment>
              <mvt:item name="ry_toolbelt" param="assign|g.sql|'SQL_SEARCH_HERE'" />
              <mvt:item name="ry_toolbelt" param="query|g.sql|results" />
          
              <mvt:comment> Get SEO link for product </mvt:comment>
              <mvt:item name="ry_toolbelt" param="seolink|product|l.all_settings:results:product_code" />
          
              <mvt:comment> Redirect to the new page </mvt:comment>
              <mvt:item name="ry_toolbelt" param="assign|g.successful|miva_output_header( 'Status', '301 Moved Permanently' )" />
              <mvt:item name="ry_toolbelt" param="assign|g.successful|miva_output_header('Location',l.all_settings:href:product)" />
          <mvt:elseif expr = "'|' $ g.screen $ '|' CIN '|ctgy|'">
              <mvt:comment> Query DB for an appropriate product </mvt:comment>
              <mvt:item name="ry_toolbelt" param="assign|g.sql|'SQL_SEARCH_HERE'" />
              <mvt:item name="ry_toolbelt" param="query|g.sql|results" />
          
              <mvt:comment> Get SEO link for product </mvt:comment>
              <mvt:item name="ry_toolbelt" param="seolink|category|l.all_settings:results:category_code" />
          
              <mvt:comment> Redirect to the new page </mvt:comment>
              <mvt:item name="ry_toolbelt" param="assign|g.successful|miva_output_header( 'Status', '301 Moved Permanently' )" />
              <mvt:item name="ry_toolbelt" param="assign|g.successful|miva_output_header('Location',l.all_settings:href:category)" />
          <mvt:else>
              <mvt:item name="ry_toolbelt" param="assign|g.successful|miva_output_header( 'Status', '302 Found' )" />
              <mvt:item name="ry_toolbelt" param="assign|g.successful|miva_output_header('Location', g.domain:name $ '/best_sellers.html')" />
          </mvt:if>
          That's a basic implementation for the NTFD page. But it works well for what it does (obviously, you'll have to set up your own testing for the SQL queries). It's also not direct MivaScript, but it translates just as well to it. This setup though, allows for the this script to only be triggered when it's necessary, rather than on every request.
          Last edited by titus; 03-25-13, 08:40 AM. Reason: Proper 302 response text
          PCINET, LLC

          Miva Merchant Design, Development, Integration & Support
          We built the most Miva Merchant stores!
          Miva shopping cart design & integration service and our Portfolio!

          e-mail: [email protected]
          web: www.pcinet.com

          "We who cut mere stones must always be envisioning cathedrals."
          Quarry Worker's Creed

          Comment


            #6
            Re: 301 redirects or work-arounds?

            I've read a little bit as far as .htaccess possibly slowing down the server since it's processed on every hit to the site. I don't know much about it myself, but from what I read it seemed like there was a lot of disagreement about the impact it has. Some people felt it was significant, others felt it wasn't, all of whom seemed knowledgeable on the subject to me. so I haven't really decided what to do about it.

            I did get the impression that if I wanted to stop using the .htaccess file I'd have to turn it off completely and move all my commands elsewhere (meaning a small .htaccess file might still be problematic since it's still called on every hit). I didn't feel like tackling that when I wasn't even sure how much of an impact it really has though

            Do you know of any way to 'benchmark' the .htaccess file?
            Looking for work as of March 2024! I've been a web developer for going on 20 years, with most of that time spent on Miva sites.

            Comment


              #7
              Re: 301 redirects or work-arounds?

              Originally posted by Mike521w View Post
              I've read a little bit as far as .htaccess possibly slowing down the server since it's processed on every hit to the site. I don't know much about it myself, but from what I read it seemed like there was a lot of disagreement about the impact it has. Some people felt it was significant, others felt it wasn't, all of whom seemed knowledgeable on the subject to me. so I haven't really decided what to do about it.

              I did get the impression that if I wanted to stop using the .htaccess file I'd have to turn it off completely and move all my commands elsewhere (meaning a small .htaccess file might still be problematic since it's still called on every hit). I didn't feel like tackling that when I wasn't even sure how much of an impact it really has though

              Do you know of any way to 'benchmark' the .htaccess file?
              The only testing I've done is with response times from scripts calling pages and the like.

              I wouldn't recommend to "stop" using the .htaccess file. It's very useful, and you can do a lot of things much more simply with it (URL rewrites, for instance), than other implementations. But it's a tool, and a tool is useful for certain types of jobs. The .htaccess file is used for HyperText Access (I know, sounds silly, but hear me out). So that means when there's access to the server over HTTP, it's going to be processed. If you're doing things which aren't necessarily global to the .htaccess element of the site (broad focus), and you can implement them better on a smaller scale (redirects for specific products that change depending on a configuration specific to the store (inventory, season), password protecting certain areas, etc.) then it's usually better to take them out of the .htaccess file, and put them in a place that is on a level that makes more sense (PROD page, NTFD page, etc.).

              Most of the time, it isn't going to break your site. So, "performance isn't always an issue". But if you're working with a high-traffic site, which has a load-balancing server to control access and all these other things to spread the strain out, it's something to consider doing.

              I've "inherited" sites which had .htaccess files that were thousands of lines long. That's not a joke. And there would be revisions upon revisions in there. It was very messy.

              Here are my two reasons that I pretty much stay out of the .htaccess file, unless it's appropriate to get in there:
              1 - It's easy to break your site if you make a mistake. Since it affects the entire site and every connection, you'll get a 500 response code, and nobody can get to the site via HTTP.

              2 - It's messier to maintain. If you're doing something that needs to be changed a lot or dynamically, it's much easier to pull it out and put it in the store.
              PCINET, LLC

              Miva Merchant Design, Development, Integration & Support
              We built the most Miva Merchant stores!
              Miva shopping cart design & integration service and our Portfolio!

              e-mail: [email protected]
              web: www.pcinet.com

              "We who cut mere stones must always be envisioning cathedrals."
              Quarry Worker's Creed

              Comment


                #8
                Re: 301 redirects or work-arounds?

                Can someone assist me with getting some simple rewrite rules working?

                Edit: Never mind.. finally got it working
                Last edited by Scott McCollough; 03-28-13, 03:25 PM.

                Comment


                  #9
                  Re: 301 redirects or work-arounds?

                  Titus,
                  This is awesome and could be really handy. Is there a way to do it with toolkit?
                  Maxanne Durkee
                  Heavyweight Collections - Premium Heavy T-Shirts
                  Facebook, Twitter, Blog

                  Comment


                    #10
                    Re: 301 redirects or work-arounds?

                    Hey, sorry for the insanely long lapse in response to you...

                    I'm absolutely certain that you can do it with the Toolkit, unfortunately, I don't use it all that often. It's a great tool, but I typically use the Tool Belt.
                    PCINET, LLC

                    Miva Merchant Design, Development, Integration & Support
                    We built the most Miva Merchant stores!
                    Miva shopping cart design & integration service and our Portfolio!

                    e-mail: [email protected]
                    web: www.pcinet.com

                    "We who cut mere stones must always be envisioning cathedrals."
                    Quarry Worker's Creed

                    Comment


                      #11
                      Re: 301 redirects or work-arounds?

                      This sounds like what I'm needing to, except for Toolkit. I'm wanting to have discontinued products & categories redirected without having to continually add lines to the .htaccess file.

                      Leslie
                      Leslie Kirk
                      Miva Certified Developer
                      Miva Merchant Specialist since 1997
                      Previously of Webs Your Way
                      (aka Leslie Nord leslienord)

                      Email me: [email protected]
                      www.lesliekirk.com

                      Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

                      Comment

                      Working...
                      X