Announcement

Collapse
No announcement yet.

A little .htaccess help please?

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

    A little .htaccess help please?

    Hi folks,

    One of my clients has a problem with bad links on some other site, and I'm trying to fix it with an .htaccess redirect. Some of the inbound URLs have a bunch of garbage after the .jpg, e.g. http://www.TheirStore.com/mm5/graphi...h_blah_etc_etc. I just want to trim off everything after the .jpg extension. I figured out the regexp, but I'm having trouble getting the rest of it to work. Can someone give me a couple of lines of code for this please?

    Also, if anyone knows of a good .htaccess tutorial on-line, please tell me; I haven't found anything real helpful.

    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
    Haven't tested, but this is probably roughly what you need:

    Code:
    RewriteCond %{REQUEST_URI} ^/mm5/graphics/00000001/(.+)\.jpg/(.+)$
    RewriteRule ^(.*)$ https://www.theirstore.com/mm5/graph...000001/%1.jpg? [R=301,L]
    Matches on /mm5/graphics/00000001/<anything>.jpg followed by a slash and any additional characters. The portion of the filename before .jpg is stored in %1. The rule issues a redirect to the filename with .jpg added back on, and the ? on the end causes the remainder of the URL to be stripped. It should only execute on URL's with the additional slash followed by zero or more characters.
    David Hubbard
    CIO
    Miva
    [email protected]
    http://www.miva.com

    Comment


      #3
      That did the trick, David. Thanks for your help, and also for the detailed explanation, which probably saved me 3-4 follow-up questions :) .
      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
        Hi David, with your help, I was able to create redirects for about 80 more bad URLs. There are just two left that I haven't been able to figure out. Oddly enough, they're old-style links with parameters. Specifically:
        Code:
        http://www.TheirStore.com/mm5/merchant.mvc?Screen=PROD&Store_Code=XXX&Product_Code=PPPP&Category_Code=
        as well as a number of URLs that contain "Screen=HNPRINT," a page code that is no longer supported. We'd like to redirect all of these to the home page, i.e. www.TheirStore.com. I tried a number of variations, but couldn't get them to work. What's the syntax for these please?

        Thanks again --
        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


          #5
          If you're okay with the conditions, you're probably just missing a question mark in the redirect. You'd want:

          RewriteRule ^(.*)$ http://www.domain.com/? [R=301,L]

          The question mark tells the browser to not put the original request back on, which is what it would normally do if redirected to just /
          David Hubbard
          CIO
          Miva
          [email protected]
          http://www.miva.com

          Comment


            #6
            Hi David, sorry to keep coming back to the well. I made that change, and tried some other things as well, but I can't get this to work. Here's what I've got so far. The first one is for a specific product page, the second is for anything that includes "Screen=HNPRINT." Both are supposed to redirect to the home page.
            Code:
            RewriteCond %{REQUEST_URI} ^/mm5/merchant\.mvc?Screen=PROD&Store_Code=XXXX&Product_Code=PPPPP&Category_Code=$ [NC]
            RewriteRule ^(.*)$ https://www.TheirDomain.com/? [R=301,L]
            
            RewriteCond %{REQUEST_URI} ^/(.+)screen=HNPRINT(.*)$ [NC]
            RewriteRule ^(.*)$ https://www.TheirDomain.com/? [R=301,L]
            What am I missing, please?

            This store's .htaccess file has a lot of other lines in it, but mine are located right below the "RewriteEngine On" statement, so I don't think the others are interfering. But if you think I should just submit a ticket on this, so that someone can look at the entire file, let me know.

            Thanks --
            Last edited by Kent Multer; 03-29-17, 11:32 AM.
            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


              #7
              Oh, that's because query strings are not considered part of REQUEST_URI. You'd want to use:

              Code:
               RewriteCond %{REQUEST_URI} ^/mm5/merchant\.mvc  
               RewriteCond %{QUERY_STRING} Screen=PROD&Store_Code=XXXX&Product_Code=PPPPP&Category_Code=$ [NC]
              and it must come above the rewrites that interpret the long URL's so the redirect happens first.
              David Hubbard
              CIO
              Miva
              [email protected]
              http://www.miva.com

              Comment


                #8
                That did the trick!

                I'm wondering if I should do something about the performance. In other threads, we've discussed the fact that too many rewrites in the .htaccess file will slow down the site. When I started on this project, the store's .htaccess file already had about 500 301's for discontinued products and categories. I thought that might be enough to produce a noticeable delay in page loads. But I tried taking them out for a few minutes, while I did some simple speed tests. The presence or absence of 500 301's didn't seem to make a difference in the page-load times. How many is too many?

                Thanks again --
                Last edited by Kent Multer; 03-29-17, 02:19 PM.
                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


                  #9
                  Hi David, one more question please. I've been asked to use server rewrites to convert all upper-case letters in URLs to lower-case. I did some searching, and it looks like this will either be really slow, or will require a RewriteMap command which we can't do on a shared server. What do you recommend? 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

                  Comment

                  Working...
                  X