Announcement

Collapse
No announcement yet.

htaccess and 301 Redirects with SEO URLs

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

    htaccess and 301 Redirects with SEO URLs

    All-

    OK, I am using MM 5.5 and have SEO URLs enabled (basically using website.com/product/product-code.html or website.com/category/category-name.html). Everything is working fine, but I need to adjust the htaccess file to do some 301 redirects on the old site's pages. So I added the Redirect 301 code to the top of the htaccess file like so:

    Redirect 301 /shop.html http://www.website.com/

    Hoping that when someone goes to the shop.html page (the old site's home page), it will redirect to the home page. Then the MM htaccess code is below it. The problem is when I go to the URL of shop.html, instead of redirecting to the home page, I get the following message in the main content:

    Page 'SFNT?Screen=shop' no longer exists.

    I assume someone else has both enabled the SEO URLs and set up 301 redirects like this. Any tips on how to do this? The site is www.wetsuitsonsale.com and the full htaccess code is below.

    Thanks in advance.

    -Bill
    Code:
    Redirect 301 /shop.html http://www.wetsuitsonsale.com/
    
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www.wetsuitsonsale.com$ [NC]
    RewriteRule ^(.*) http://www.wetsuitsonsale.com/$1 [L,R=301]
    
    ### Begin - Inserted by Miva Merchant
    
    DirectoryIndex /mm5/merchant.mvc?Screen=SFNT
    
    RewriteEngine On
    
    RewriteRule ^mm5/admin.mvc? - [L]
    
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^product/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Product_code=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^category/([^/.]+).html$ /mm5/merchant.mvc?Screen=CTGY&Category_code=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^product/([^/]+)/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Category_code=$1&Product_code=$2 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^([^/.]+).html$ /mm5/merchant.mvc?Screen=$1 [L]
    
    ### End - Inserted by Miva Merchant

    #2
    Re: htaccess and 301 Redirects with SEO URLs

    Let's follow this through:
    the url we're working on in blue

    http://website.com/shop.html

    Redirect 301 /shop.html http://www.wetsuitsonsale.com/

    http://www.wetsuitonsale.com/


    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www.wetsuitsonsale.com$ [NC]
    RewriteRule ^(.*) http://www.wetsuitsonsale.com/$1 [L,R=301]

    *no change

    ### Begin - Inserted by Miva Merchant

    DirectoryIndex /mm5/merchant.mvc?Screen=SFNT

    *tacks on the index and so now we're working on
    http://www.wetsuitonsale.com/mm5/mer...vc?Screen=SFNT

    RewriteEngine On

    RewriteRule ^mm5/admin.mvc? - [L]
    *doesn't apply

    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^product/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Product_code=$1 [L]
    *doesn't apply so nothing happens

    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^category/([^/.]+).html$ /mm5/merchant.mvc?Screen=CTGY&Category_code=$1 [L]
    *doesn't apply so nothing happens

    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^product/([^/]+)/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Category_code=$1&Product_ code=$2 [L]
    *doesn't apply so nothing happens

    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^([^/.]+).html$ /mm5/merchant.mvc?Screen=$1 [L]
    *should not have applied, yet it did. And it appears like the rules are still working on shop.html.
    SO... let's look back at where it should no longer have been shop.html in the url.
    Redirect 301 /shop.html http://www.wetsuitsonsale.com/
    obviously didn't work.

    Does your server have Mod_Redirect enabled? I'm guessing maybe not.
    Mod_Redirect is the best choice for this kind of redirect because it's the least server intensive. But if you don't have it and your host won't give it to you. Then you'll have to use Mod_Rewrite instead to do the same thing.

    Before your last rule, you'll have to insert another rewrite cond and rule pair. You'll do a RewriteCond that checks for the
    REQUEST_URI* shop.html
    and Rewriterule it. Also in the [] instead of just a L you would put [R=301,L]. that r=301 will tell the server to give 301 headers on the shop.html request and then give the new correct content with a 200 response.

    *request_uri grabs what looks to be the file name in the url address. For your purposes for the shop.html you do not want to use request_filename like you see in those rewrites that miva created for you. It does a little bit different thing.

    Comment


      #3
      Re: htaccess and 301 Redirects with SEO URLs

      Thanks for the assist. The host is Hostasaurus and I'm not sure if the server has Mod_Redirect enabled, but I'll put in a ticket to ask.

      I completely suck at writing conditions and rules for htaccess, so I understand what you want me to do, I'm just pretty clueless about how to do it. Here is my first crack at the new condition/rule, but I'm pretty confused about how I'd construct the syntax to do it.

      RewriteCond %{REQUEST_URI} !-s
      RewriteRule ^([^/.]+).html$ /mm5/merchant.mvc?Screen=$1 [R=301,L]

      If you can give me a little more of a nudge, I'll see if I can figure it the rest of the way.

      Thanks again.

      -Bill

      Comment


        #4
        Re: htaccess and 301 Redirects with SEO URLs

        The issue is not related to the rewrites or redirects, it's Miva's use of ?Screen=SFNT on the directoryindex which is not necessary since requesting merchant.mvc with no arguments produces the storefront page anyway. So first thing to do is change your directoryindex line to:

        DirectoryIndex /mm5/merchant.mvc

        Next, since redirecting a browser from /something to / usually causes the browser to add what was previously requested right back on, you'll want to change the redirect to:

        Redirect 301 /shop.html http://www.wetsuitsonsale.com/?

        That will cause the browser to strip off the previous URL.
        David Hubbard
        CIO
        Miva
        [email protected]
        http://www.miva.com

        Comment


          #5
          Re: htaccess and 301 Redirects with SEO URLs

          The way I would do it would be putting in the following line in your .htaccess file anywhere below the RewriteEngine On line:

          Code:
          RewriteRule ^shop.html http://www.wetsuitsonsale.com [L,R=301]
          Last edited by morditech.com; 08-26-09, 08:35 PM.

          Comment


            #6
            Re: htaccess and 301 Redirects with SEO URLs

            Without the changes I mentioned your suggestion will produce the same error that is already being seen.
            David Hubbard
            CIO
            Miva
            [email protected]
            http://www.miva.com

            Comment


              #7
              Re: htaccess and 301 Redirects with SEO URLs

              You may be right but I tried this on a site that has the exact .htaccess file with the exception of the domain name and it worked without putting in the extra characters in the URL.

              Comment


                #8
                Re: htaccess and 301 Redirects with SEO URLs

                Hostasaurus is a great host. They have never steered me wrong.

                I'd have to bet a lot in vegas that what hostasaurus says will work on their own servers, will work.

                Comment


                  #9
                  Re: htaccess and 301 Redirects with SEO URLs

                  Your probably right, he is probably right. I am just saying I tried it and it worked that's all.

                  Comment


                    #10
                    Re: htaccess and 301 Redirects with SEO URLs

                    I had a thought.. what if the site had name value pairs on the shop.html address. Maybe some tracking value or affilaite code, etc. something like

                    www.example.com/shop.html?a=affiliatecode&b=myspecialvariable

                    wouldn't the Redirect with question mark strip those off?
                    Redirect 301 /shop.html http://www.wetsuitsonsale.com/?

                    Maybe something sorta like these next examples would keep those intact and only apply ot the shop.html address?

                    RewriteCond %{REQUEST_URI} ^shop\.html$
                    RewriteRule ^shop\.html$ http://www.example.com/ [R=301,L]

                    if there are any name value pairs, i think they'll be preserved.

                    but if that doesn't.. then maybe something more like this.

                    RewriteCond %{REQUEST_URI} ^shop\.html$
                    RewriteCond %{QUERY_STRING} ^(.*)$
                    RewriteRule ^shop\.html$ http://www.example.com/?%1 [R=301,L]

                    I'm not in a place to test these right now on a server, or I would.
                    Last edited by kayakbabe; 08-26-09, 11:46 PM.

                    Comment


                      #11
                      Re: htaccess and 301 Redirects with SEO URLs

                      OK, I tried both the suggestion from David with Hostasaurus (and it worked as advertised) and the suggestion for Morditech and that also worked. I reverted to how it was before the Hostasaurus changes were made. So I'm not sure what is going on, but it looks like I went to having two solutions. Thanks!

                      I am a bit concerned that the one redirect would strip off the some tracking codes though. This customer does quite a bit of Google Adwords work and I have the tracking codes enabled for Google Analytics. They never used it before, but I've enabled it and think they'd find it very interesting if they could have that working.

                      Regardless, thanks for everyone's help. I couldn't have figured this out without it.

                      -Bill

                      Comment


                        #12
                        Re: htaccess and 301 Redirects with SEO URLs

                        I have just started the SEO short links & now want to change my category codes into category names to get better search engine placement. So, I want to change category "CicciaBella" that shows up in URL as http://www.cielgallery.net/category/CF.html to show up as http://www.cielgallery.net/category/cicciabella.html and so on with the subcategories. I've tried to start it & test it & haven't done something right. I'm also not sure how to do the subcategories & if that changes anything. This is what I started with in my htaccess file:

                        RewriteEngine on
                        rewritecond %{http_host} ^cielgallery.net [nc]
                        rewriterule ^(.*)$ http://www.cielgallery.net/$1 [r=301,nc]

                        redirect 301 /mm5/merchant.mvc?Screen=CTGY&Store_Code=CG&Category_Co de=CF http://www.cielgallery.net/category/CicciaBella/

                        The newest addition that changed my long links to short links:

                        ### Begin - Inserted by Miva Merchant
                        RewriteEngine On
                        RewriteRule ^mm5/admin.mvc? - [L]
                        RewriteCond %{REQUEST_URI} !-s
                        RewriteRule ^product/([^/.]+).html /mm5/merchant.mvc?Screen=PROD&Product_code=$1 [L]

                        RewriteCond %{REQUEST_URI} !-s
                        RewriteRule ^category/([^/.]+).html /mm5/merchant.mvc?Screen=CTGY&Category_code=$1 [L]

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

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

                        ### End - Inserted by Miva Merchant

                        Thanks, any help is so appreciated.

                        Comment


                          #13
                          Re: htaccess and 301 Redirects with SEO URLs

                          You must use the category code somewhere consistently in your url.
                          That way you can translate your short url into something that miva merchant can actually use.

                          http://www.cielgallery.net/category/CicciaBella/

                          will not work.
                          but something like
                          http://www.cielgallery.net/category/CE-CicciaBella/
                          could be doable.
                          or
                          http://www.cielgallery.net/category/CE/CicciaBella/
                          could also be doable.

                          Comment


                            #14
                            Re: htaccess and 301 Redirects with SEO URLs

                            Yes, either would be great. My problem is I cannot seem to get the code right. I think the problem may be in the htaccess file. Could you give me an example of what that rewrite would look like... I'm new to this.
                            Thank you!

                            Comment


                              #15
                              Re: htaccess and 301 Redirects with SEO URLs

                              Originally posted by ILoveHostasaurus View Post
                              The issue is not related to the rewrites or redirects, it's Miva's use of ?Screen=SFNT on the directoryindex which is not necessary since requesting merchant.mvc with no arguments produces the storefront page anyway. So first thing to do is change your directoryindex line to:

                              DirectoryIndex /mm5/merchant.mvc

                              Next, since redirecting a browser from /something to / usually causes the browser to add what was previously requested right back on, you'll want to change the redirect to:

                              Redirect 301 /shop.html http://www.wetsuitsonsale.com/?

                              That will cause the browser to strip off the previous URL.

                              Hello David, my name is Aaron and I am having the same issue as the posted you replied to above.

                              I followed your advice and here is the code I am using in my .htaccess..

                              I want to redirect

                              /relay.html
                              to
                              /product/RELAY.html

                              I realize it seems weird to redirect to the same filename, just capitol letters, but the reason is the old site was static html pages, not miva pages, they passed form data to merchant to sell items. Now, using inventory variants, thats the name of the master product. Not all of the products are this way, I guess I just chose a bad example.

                              Code:
                              Redirect 301 /index.html http://www.eaglesnestoutfittersinc.com/?
                              Redirect 301 /relay.html http://www.eaglesnestoutfittersinc.com/product/RELAY.html?
                              
                              
                              
                              
                              
                              ### Begin - Inserted by Miva Merchant
                              
                              DirectoryIndex /mm5/merchant.mvc
                              
                              RewriteEngine On
                              
                              RewriteRule ^mm5/admin.mvc? - [QSA,L]
                              
                              RewriteCond %{REQUEST_FILENAME} !-s
                              RewriteRule ^product/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Product_code=$1 [QSA,L]
                              
                              RewriteCond %{REQUEST_FILENAME} !-s
                              RewriteRule ^category/([^/.]+).html$ /mm5/merchant.mvc?Screen=CTGY&Category_code=$1 [QSA,L]
                              
                              RewriteCond %{REQUEST_FILENAME} !-s
                              RewriteRule ^([^/]+)/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Category_code=$1&Product_code=$2 [QSA,L]
                              
                              RewriteCond %{REQUEST_FILENAME} !-s
                              RewriteRule ^([^/.]+).html$ /mm5/merchant.mvc?Screen=$1 [QSA,L]
                              
                              ### End - Inserted by Miva Merchant
                              If I remove the ? at the end of the string, the redirect breaks & I get this again (like before the changes in your post)
                              http://www.eaglesnestoutfittersinc.c...l?Screen=relay

                              The issue is that the ? stays in the URL. Although I am directed to the right page, the URL is
                              http://www.eaglesnestoutfittersinc.c...ct/RELAY.html?

                              instead of

                              http://www.eaglesnestoutfittersinc.c...uct/RELAY.html


                              Is there a way to strip the trailing ?

                              Does it perhaps have something to do with the QSA


                              RewriteCond %{REQUEST_URI} ^relay\.html$
                              RewriteRule ^relay\.html$ http://www.eaglesnestoutfittersinc.com/ [R=301,L]

                              if there are any name value pairs, i think they'll be preserved.

                              but if that doesn't.. then maybe something more like this.

                              RewriteCond %{REQUEST_URI} ^relay\.html$
                              RewriteCond %{QUERY_STRING} ^(.*)$
                              RewriteRule ^relay\.html$ http://www.eaglesnestoutfittersinc.com/?%1 [R=301,L]
                              I also tried the above, but got the same URL I typed (but this time with a not found message)
                              http://www.eaglesnestoutfittersinc.com/relay.html - miva not found page it used to redirect to
                              http://www.eaglesnestoutfittersinc.c...l?Screen=relay with my code above.

                              Thank you in advance.
                              Aaron

                              Comment

                              Working...
                              X