Announcement

Collapse
No announcement yet.

re-write rule in .htaccess

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

    re-write rule in .htaccess

    The search engines have been crawling my site and coming up with some bogus URLs that they use, they follow a format for multiple products so I would like to a re-write rule instead of using 301 redirects for everyone. I have been successful in fixing most of the issues but I am stuck on one. I am not sure if it because the bogus code being inserted is a CTGY...the link is:

    https://www.execshirts.com/dress-shi...gory_Code=.htm

    It is inserting &Category_Code= in the middle of the proper link and I need a way to remove that for multiple products. I tried the following re-write in my .htaccess but it did not work:

    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^&Category_Code=.htm$ .htm [R=301,NC,L]

    Anyone have any ideas? Thanks.

    #2
    For things in the query string, you have to touch those with a condition as the rule doesn't see those on the matching side. So it would look like this:

    RewriteCond %{QUERY_STRING} ^&Category_Code=.htm$
    RewriteRule ^(.*)$ $1? [R=301,L]

    The question mark in the rule is the critical part; that will strip the pre-existing query string. Keep in mind that you will see the question mark in the resulting URL, there's no way around that, but search engines treat http://blah and http://blah? as the same thing, so you don't have to worry about that part.
    David Hubbard
    CIO
    Miva
    [email protected]
    http://www.miva.com

    Comment


      #3
      There is no ? anywhere in the given link, so there is no query string that has to be processed

      ^ -- means beginning of the string, which is not in your case
      . -- means ANY character, which is not in your case (must be \. for period)

      Try something like that:
      Code:
      RewriteRule ^(.*)&Category_Code=\.htm$ /$1.htm [R=301,NC,L]
      It should extract unwanted part of the URL and will redirect to /dress-shirts/TIPURBA.htm

      should be inserted into the .htaccess ABOVE miva rules
      Last edited by AHerb; 07-10-17, 11:08 AM.

      Comment


        #4
        Ah oops, Category_Code is a traditional Merchant query string parameter, I didn't notice it was &Category_Code=.htm rather than ?Category_Code=.htm.
        David Hubbard
        CIO
        Miva
        [email protected]
        http://www.miva.com

        Comment


          #5
          Thanks that worked...I have some other examples I need to fix but have a more general question about how re-directs should work in Miva. I have been using Miva for about 14 years and I get some crazy 404's from the search engines. I am still getting 404 errors for /Merchant2/ even though I have not had any links like that for over 7 years. When I changed to Miva 5 I changed the Product page to be /dress-shirts/ and for a couple of years now I have been using the URI function for the Product Pages. I have over 400 products for sale but they can be accessed from multiple links...so over 1200 links for 400 products??? I have a gut feeling that this is hurting me in the search engines. For example, I sell a Red Broadcloth Dress Shirt and all the links on my site conform to the URI methodology so the proper product link is:

          https://www.execshirts.com/dark-red-broadcloth-dress-shirt.htm

          But you can also access this page using the old /dress-shirts/ methodology:

          https://www.execshirts.com/dress-shirts/DKREDBR.htm

          And to further complicate matters you can access using the old Miva methodology:

          https://www.execshirts.com/?Screen=P...t_Code=DKREDBR

          And you can do this with any of the 400+ products that I sell. Is that normal? Is that correct? Does it need to be changed? If it is fine I will not worry about it but it seems spammy to me. Shouldn't everything be linked using the URI methodology with re-directs? Do I have to go in to each product and add 2 re-directs to get everything to follow the URI methodology?

          Thanks for your time...

          Comment


            #6
            The ideal option, which may not be easy to get to depending on your store's coding/template, would be the built-in URI Management features from more recent versions. You can set the desired URL for a given product, along with any other URL that had pointed at it in the past, and the store can be told to 301 redirect any request that came in on the old links. Then you don't have a ton of htaccess rules slowing your site down, and you manage it all in Merchant.
            David Hubbard
            CIO
            Miva
            [email protected]
            http://www.miva.com

            Comment


              #7
              Thanks David I went through my URI management and even tried the update .htaccess page function and it basically broke my site. The ctgy/prod page came up as not found...it added this text below:

              ### Begin - Inserted by Miva Merchant

              DirectoryIndex /mm5/merchant.mvc

              RewriteEngine On

              RewriteRule ^mm5/admin.mvc? - [QSA,L]

              RewriteCond %{REQUEST_FILENAME} !-s
              RewriteRule ^dress-shirts/([^/.]+).htm$ /mm5/merchant.mvc?Screen=PROD&Product_code=$1 [QSA,L]

              RewriteCond %{REQUEST_FILENAME} !-s
              RewriteRule ^shirts/([^/.]+).htm$ /mm5/merchant.mvc?Screen=CTGY&Category_code=$1 [QSA,L]

              RewriteCond %{REQUEST_FILENAME} !-s
              RewriteRule ^([^/]+)/([^/.]+).htm$ /mm5/merchant.mvc?Screen=PROD&Category_code=$1&Product_ code=$2 [QSA,L]

              RewriteCond %{REQUEST_FILENAME} !-s
              RewriteRule ^([^/.]+).htm$ /mm5/merchant.mvc?Screen=$1 [QSA,L]

              ### End - Inserted by Miva Merchant

              I had to remove all of that since my site would not work with the coding still in there. I am assuming that I have an older version of URI that prevents me from doing the easy thing. Is there a re-write option that I can put in that would force any miva prod coding to convert to URI or do you think I have to manually go in and change all of them? I am assuming that I should fix this issue one way or the other since it is probably affecting me...correct? Thanks for your time.

              Comment


                #8
                Those are the older rewrites Merchant would put in when you enable URL prefix/suffix, short links, etc. The "URI Management" is a new feature and you'll end up with this in your htaccess:

                ### Begin - Miva Merchant URI Management: Direct all non-file URIs to Miva Merchant
                RewriteEngine on
                RewriteCond %{REQUEST_FILENAME} !-s
                RewriteCond %{REQUEST_URI} !^/mm5/.*$
                RewriteRule ^(.*)$ /mm5/uri.mvc? [QSA,L]
                ### End - Miva Merchant URI Management

                It has to be handled carefully getting it into an existing site since it may conflict with existing rewrites in the file, as well as other applications, such as if you're also running Wordpress with permalinks, which handles those in the same way, where it wants to see all requests for non-existent files.

                I'm not knowledgeable enough about URI Management to be able to say if you should be able to just switch it on without breaking existing URL structures, or if there's some pre-populating of data that should be done first, etc. I'd recommend you have our support team set up a dev site and try turning it on there to play with it and see how it works.
                David Hubbard
                CIO
                Miva
                [email protected]
                http://www.miva.com

                Comment


                  #9
                  I am afraid that inserting that string did not work...the only thing that I tried that had any affect is when I deleted this old string:

                  RewriteCond %{REQUEST_FILENAME} !-s
                  RewriteRule ^([^/]+)/([^/.]+).htm$ /mm5/merchant.mvc?Screen=PROD&Category_code=$1&Product_ code=$2 [QSA,L]

                  The link for /dress-shirts/xxxxxxx.htm did not work any more, it comes back "Not Found"...the other Miva Prod link and the URI link still work fine. The only thing that I am worried about is the Prod links. I know that the URI is working because with this removed it still works. Is there a re-write I can use that would take anything with /dress-shirts/ in it and redirect it to the page using the URI link? If not, I guess I could write a re-write directing any of those old links back to the homepage. Of course I would need to use the same methodology on the Miva Prod link. I looked at my URI.mvc file and it is dated 8/2015 if that helps. Thanks...

                  Comment


                    #10
                    So I tried everything and I cannot get it to work...it seems the URI re-write is overriding any attempt to do a re-direct...or it causes a 500 error that shuts down the site. I even went to my development (dts) site and copied the URI.mvc file and loaded it onto my site...it was a year newer but did not change anything. I then went ahead and did a bunch of 301 re-directs, for example:

                    Redirect 301 /dress-shirts/DKREDBR.htm https://www.execshirts.com/dark-red-...ress-shirt.htm
                    Redirect 301 ?Screen=PROD&Store_Code=E&Product_Code=DKREDBR https://www.execshirts.com/dark-red-...ress-shirt.htm

                    The one for /dress-shirts/ is now re-directing to the canonical URI as it is supposed to

                    The legacy Miva one does not work...so I am out of solutions...I think this change MUST be made in the URI management. Would uploading a brand new URI.mvc work?

                    I re-read the documentation for URI management and made sure that <link rel="canonical" href="&mvte:product:link;" /> was present in the head tag on my product pages.

                    I have tried everything I can on my end...but need some guidance...

                    Comment


                      #11
                      This is not something we can really troubleshoot via a forum; it needs to go through the technical assistance folks. Whatever is causing the problem will depend entirely on your templates, if a theme is involved, what other rules are in the htaccess, so on and so forth. The uri.mvc file is simply a very very low impact script designed to just do URI lookups and either invoke Merchant to serve the full content, or issue redirects, so it hasn't changed in a while and should be very small; it wouldn't be the problem. Knowing the complexity of your site, it may require a professional services engagement.
                      David Hubbard
                      CIO
                      Miva
                      [email protected]
                      http://www.miva.com

                      Comment


                        #12
                        Originally posted by execshirts View Post
                        So I tried everything and I cannot get it to work...it seems the URI re-write is overriding any attempt to do a re-direct...or it causes a 500 error that shuts down the site.
                        All rules are processed in order, so "earlier" rules will overwrite rules below.

                        upload you entire .htaccess file somewhere like... pastebin.org and give us a link to have a quick look at it



                        Comment

                        Working...
                        X