Announcement

Collapse
No announcement yet.

URI force www in htaccess with uri.mvc

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

    URI force www in htaccess with uri.mvc

    How do you force www in the .htaccess with the new uri.mvc module?

    I tried the example from the infographic but I think it may be outdated.

    I get a uri.mvc Not Found error.
    http://www.alphabetsigns.com/

    #2
    Re: URI force www in htaccess with uri.mvc

    Nothing should change. What code are you using and where are you putting it? Make sure it is above the code Miva adds.
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Re: URI force www in htaccess with uri.mvc

      I'm placing this code at the top of the .htaccess. The Miva URI Management section is at the very bottom. I'm also forcing secure protocol. I'm thinking it's something wrong with my code, maybe missing an L.

      Code:
      # force https
      RewriteEngine On
      RewriteCond %{HTTPS} off
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
      
      
      # force www
      RewriteCond %{HTTP_HOST} !^www.alphabetsigns.com
      RewriteRule ^(.*)$ https://www.alphabetsigns.com/$1 [R=301]
      http://www.alphabetsigns.com/

      Comment


        #4
        Re: URI force www in htaccess with uri.mvc

        My homepage doesn't have a trailing slash but its canonical tag (urls:_self:auto) does.

        Is this something that can be set through the URI Manager or forced in htaccess?
        http://www.alphabetsigns.com/

        Comment


          #5
          Re: URI force www in htaccess with uri.mvc

          Code:
          # force www
          RewriteCond %{HTTP_HOST} !^www.alphabetsigns.com
          RewriteRule ^(.*)$ https://www.alphabetsigns.com/$1 [R=301]
          That is valid, however, you are correct that it would be better to have the L in the options list. L tells apache to not process any further rewrites, which is exactly what you want in this case, because you want the request to be redirected to the same thing with www on the front at that point instead of having the rest of the URL parsed.

          I'd add it back in, after the force secure code, since more requests will hit the non-secure rewrite, so may as well have it kill two birds with one stone rather than needing two redirects. I'd simplify the force secure too:

          Code:
          # force https
          RewriteEngine On
          RewriteCond %{HTTPS} off
          RewriteRule (.*) https://www.alphabetsigns.com/$1 [R=301,L]
          
          # force www
          RewriteCond %{HTTP_HOST} !^www.alphabetsigns.com
          RewriteRule ^(.*)$ https://www.alphabetsigns.com/$1 [R=301,L]
          David Hubbard
          CIO
          Miva
          [email protected]
          http://www.miva.com

          Comment


            #6
            Re: URI force www in htaccess with uri.mvc

            Thanks David,

            That solved the force www. issue.

            I'm still confused by the trailing slash issue. The home page renders correctly but there is no trailing slash in the address bar so I'm wondering if the uri.mvc module is rewriting the homepage without a slash. That would make sense as the URI Manager requires all uris to be created with an opening slash.

            From the page source code, I can tell the homepage canonical link renders correctly with a trailing slash and any link to urls:SFNT page renders correctly with a trailing slash but the address bar does not end with a trailing slash. I even hardcoded a homepage link with a trailing slash but it is rewritten without one.

            Are www.homepage.com and www.homepage.com/ two different urls?

            I always thought the trailing slash made the server look in a directory for an index page but then it became a standardized look as one navigates through a site. I do not have a Directory index directive in the htaccess. My main concern is that the canonical homepage tag is the same as the address bar and I am not creating duplicate content.
            http://www.alphabetsigns.com/

            Comment


              #7
              Re: URI force www in htaccess with uri.mvc

              My understanding is that www.homepage.com and www.homepage.com/ are the same from Google's perspective, as is www.homepage.com/? They're pretty smart, so I would not worry about that. The actual slash disappearing appears to be something the browser itself is doing for whatever reason. I tried a bunch of sites in Chrome just now and all removed the slash even if I typed the URL in with it.
              David Hubbard
              CIO
              Miva
              [email protected]
              http://www.miva.com

              Comment


                #8
                Re: URI force www in htaccess with uri.mvc

                How about that.

                The trailing slash appears in IE and Safari but not FF or Chrome. I double checked it on other sites as well.

                I'm not sure why but I read that it may be to being able to search in Chrome from the address bar. FF has a browser flag that can be set.

                Thanks for looking into it further!
                http://www.alphabetsigns.com/

                Comment


                  #9
                  Re: URI force www in htaccess with uri.mvc

                  I'm tagging in on this since the subject has "force www in htaccess"

                  Store has the following in place

                  Code:
                  RewriteEngine On
                  
                  #RewriteCond %{HTTP_HOST} ^domain\.com [NC]
                  #RewriteRule (.*) http://www.domain.com/$1 [L,R=301]
                  It's my understanding this is supposed to force the www to be used. It is not working.




                  ps...I tried using the forum search since I'm sure there are other examples, but the forum search has become useless.
                  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


                    #10
                    Re: URI force www in htaccess with uri.mvc

                    Well <mvt:doh> I see my problem </mvt:doh>
                    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


                      #11
                      Re: URI force www in htaccess with uri.mvc

                      Hey Leslie,

                      Glad you found it. Not sure which way you ended going with but I prefer David's example..

                      The !^ symbols mean anything that does not begin with www.domain.com. It is a negative match that covers a wider number of circumstances including typos such as wwww or ww. or qww or wwe, (you get it).
                      http://www.alphabetsigns.com/

                      Comment


                        #12
                        Re: URI force www in htaccess with uri.mvc

                        Question, why wouldn't you just change your Base URL under Domain Settings to be the same as Secure Base URLs?
                        Bruce Golub
                        Phosphor Media - "Your Success is our Business"

                        Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                        phosphormedia.com

                        Comment


                          #13
                          Re: URI force www in htaccess with uri.mvc

                          The htaccess can resolve inbound links and bookmarks that we can't control. It also resolves any hardcoded links in the css or js files.
                          http://www.alphabetsigns.com/

                          Comment


                            #14
                            Re: URI force www in htaccess with uri.mvc

                            So you are doing both?

                            I'm no expert, but I don't think at least google cares if an inbound link is https or http. Now, they are, apparently, giving a little more credence to sites that serve pages using https, but google isn't using inbound links to make *that* distinction.

                            as for css, js and other resources, if day usin' hard-coded links...well, fix em :)
                            Bruce Golub
                            Phosphor Media - "Your Success is our Business"

                            Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                            phosphormedia.com

                            Comment


                              #15
                              Re: URI force www in htaccess with uri.mvc

                              Hey Bruce,

                              Yea I'm doing both. The Base URL was the first thing I changed. The .htaccess redirect for incoming links was done for humans not Google. G currently has more emphasis on thin content and site quality. I can't say that I see much SEO boost from SSL and it wasn't the reason I did it. And if you are working with a team or libraries those hard coded links happen. So it gives you time to root them out later.

                              I headed the direction of SSL for 2016 ngnix http2 module but then realized that my CDN already uses SPDY so it turns out there was no rush.

                              Nonetheless, the overhead of SSL just isn't there so I wouldn't shy away from it. Here's a typical page load:

                              Code:
                              Request Start: 0.282 s
                              DNS Lookup: 77 ms
                              Initial Connection: 59 ms
                              SSL Negotiation: 97 ms
                              Time to First Byte: 494 ms
                              Content Download: 74 ms
                              Bytes In (downloaded): 8.1 KB
                              Bytes Out (uploaded): 0.3 KB
                              
                              
                              http://www.alphabetsigns.com/

                              Comment

                              Working...
                              X