Announcement

Collapse
No announcement yet.

.htaccess redirect with product and category in the URL

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

    .htaccess redirect with product and category in the URL

    I'm trying to redirect a number of long style product URLs that have the category codes in them to the short style URL
    HTML Code:
    http://www.domain.com/Merchant2/merchant.mvc?Screen=PROD&Store_Code=ABC&Product_Code=XYZ&Category_Code=123

    Here's what is already in place
    Code:
    ### Begin - Dynamic to Short Link 301 Redirect
    
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^product/([^/.]+).html$ /Merchant2/merchant.mvc?Screen=PROD&Product_code=$1 [QSA,L]
    
    
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^category/([^/.]+).html$ /Merchant2/merchant.mvc?Screen=CTGY&Category_code=$1 [QSA,L]
    
    
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^([^/]+)/([^/.]+).html$ /Merchant2/merchant.mvc?Screen=PROD&Category_code=$1&Product_code=$2 [QSA,L]
    
    
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^([^/.]+).html$ /Merchant2/merchant.mvc?Screen=$1 [QSA,L]
    
    
    ### End - Inserted by Miva Merchant
    
    
    RewriteCond %{QUERY_STRING} ^Screen=CTGY&Store_Code=ABC&Category_Code=(.*)$
    RewriteRule ^(.*)$ http://www.domain.com/category/%1.html? [R=301,L]
    
    
    
    
    RewriteCond %{QUERY_STRING} ^Screen=PROD&Store_Code=ABC&Product_Code=(.*)$
    RewriteRule ^(.*)$ http://www.domain.com/product/%1.html? [R=301,L]
    I did try this

    Code:
    RewriteCond %{QUERY_STRING} ^Screen=PROD&Store_Code=ABC&Product_Code=(.*)&Category_Code=(.*)$RewriteRule ^(.*)$ http://www.domain.com/product/%1.html? [R=301,L]
    but still wound up with a URL like this
    HTML Code:
    http://www.domain.com/product/productcode&Category_Code=123.html
    what am I missing?

    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

    #2
    Re: .htaccess redirect with product and category in the URL

    This:

    RewriteCond %{QUERY_STRING} ^Screen=PROD&Store_Code=ABC&Product_Code=(.*)$
    RewriteRule ^(.*)$ http://www.domain.com/product/%1.html? [R=301,L]

    would match on both:

    Screen=PROD&Store_Code=ABC&Product_Code=XYZ&Catego ry_Code=123

    and

    Screen=PROD&Store_Code=ABC&Product_Code=XYZ

    because .* means zero or more of anything. Try changing that one to:

    RewriteCond %{QUERY_STRING} ^Screen=PROD&Store_Code=ABC&Product_Code=([^&]*)
    RewriteRule ^(.*)$ http://www.domain.com/product/%1.html? [R=301,L]

    That should match on the text of the value up to anything but ampersand, so if there isn't one, no problem, if there is one, it and whatever comes after it are ignored.
    David Hubbard
    CIO
    Miva
    [email protected]
    http://www.miva.com

    Comment


      #3
      Re: .htaccess redirect with product and category in the URL

      Thank you David, that fixed it right up!
      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