Announcement

Collapse
No announcement yet.

.htaccess https to http question

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

    .htaccess https to http question

    Hi

    I have spent a couple of hours this morning trying to ensure I use the correct text in the .htaccess file to redirect http://.domain.com to the www. version and also https://www.domain.com to the non https version.

    The code I used is:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^performancemotorcare.com$ [nc]
    Rewriterule ^(.*)$ http://www.performancemotorcare.com/$1 [r=301,nc]

    RewriteEngine On
    RewriteCond %{HTTPS} on
    Rewriterule ^(.*)$ http://www.performancemotorcare.com/$1 [r=301,nc]

    However the problem I am having is https://performancemotorcare.com which then routes to
    http://www.performancemotorcare.com/...motorcare.com/ - which does not exist as a page and looks awful on the screen.

    Is there something very simple I am missing or is my approach the wrong one.

    Any help would be appreciated.

    Thanks

    Rob
    Rob
    For all your car, motorcycle and marine care, cleaning and detailing products.

    #2
    I don't think you need to direct the https version to the http version - have you tried it without that bit?

    The net effect of what you're doing is that everything is going to:

    http://www.performancemotorcare.com/http://www.performancemotorcare.com/

    Which looks awful probably because it can't find its images or CSS.

    Aquazuro - designer stainless steel accessories

    Comment


      #3
      Mark

      Many thanks. The reason we are looking to do it is that we appear to have canonicalization issues. Specifically, some pages in Google's index are from www.performancemotorcare.com, some from performancemotorcare.com, and some from https://www.performancemotorcare.com. This is potentially creating duplicate content and PageRank dilution.

      It may be that there aren't any pages in https://performancemotorcare.com and that the scenario will not occur unless I specifically type it - which is where I relaised it was happening in testing all variations?

      Regards

      Rob
      Rob
      For all your car, motorcycle and marine care, cleaning and detailing products.

      Comment


        #4
        What you want to do is add:-

        Code:
        RewriteEngine on
        Options +FollowSymlinks
        RewriteCond %{SERVER_PORT} ^443$
        RewriteRule ^robots.txt$ robots_ssl.txt
        to your .htaccess then create a file called robots_ssl.txt in your root with the following inside it:-

        Code:
        User-agent: *
        Disallow: /
        Once you've done all that go to https://yourdomain.com/robots.txt and you should find it displays the ssl version.
        Cheers

        David
        Located in Edinburgh UK

        http://twitter.com/mcfinster

        Comment


          #5
          Dave

          Many thanks. That looks like a neat solution to the problem. I note the reference ^robots.txt$ - will the existing robots.txt file continue to be referenced as normal for non https?

          Regards
          Rob
          For all your car, motorcycle and marine care, cleaning and detailing products.

          Comment


            #6
            Yes. Just visit the robots.txt in the browser after you've made the changes and make sure the http version shows different content to the https version
            Cheers

            David
            Located in Edinburgh UK

            http://twitter.com/mcfinster

            Comment


              #7
              Thanks Dave. Confirm all looking as it should with both files displaying the different content. Just need to wait for Google to pick up on this and stop indexing the https. Many thanks again for your help.

              Regards
              Rob
              For all your car, motorcycle and marine care, cleaning and detailing products.

              Comment


                #8
                Aye, took a few weeks for our to drop off but they do eventually!
                Cheers

                David
                Located in Edinburgh UK

                http://twitter.com/mcfinster

                Comment


                  #9
                  I did do a 'thanks' but just wanted to say again that this is a cracking fix! Thank you.
                  Jonathan Chappell
                  Website Designer
                  SellerDeck Website Designer
                  Actinic to SellerDeck upgrades
                  Graphicz Limited - www.graphicz.co.uk

                  Comment


                    #10
                    SSL and htaccess

                    Originally posted by dave_finlayson View Post
                    What you want to do is add:-

                    Code:
                    RewriteEngine on
                    Options +FollowSymlinks
                    RewriteCond %{SERVER_PORT} ^443$
                    RewriteRule ^robots.txt$ robots_ssl.txt
                    to your .htaccess then create a file called robots_ssl.txt in your root with the following inside it:-

                    Code:
                    User-agent: *
                    Disallow: /
                    Once you've done all that go to https://yourdomain.com/robots.txt and you should find it displays the ssl version.
                    Hello everyone,

                    Im about to sign up with a host that applies ssl to every page which means all my google links will be dead as it will no longer be http but https, am I right in saying all I need to do is to open notepad, put the above code in, call it .htaccess and ftp it to the server root, or have I got it all wrong ? Is there a better thread on the forums for this ?

                    Thanks,

                    Michael
                    Kind regards,

                    Michael

                    www.stageprint.co.uk

                    Comment


                      #11
                      Doesn't Work with some Hosting Companies

                      This doesn't work with my Hosting company (Heart)

                      Here is my dialogue with them:

                      The SSL is across the whole site but it is only used on the login and checkout pages.

                      Therefore I wanted to stopp Google indexing the SSL versions of the main site pages.

                      I did what I have done before: ie:
                      create robots.txt -
                      User-agent: *
                      Allow: /
                      create robots_ssl.txt -
                      User-agent: *
                      Dissallow: /

                      And add this line to htaccess:

                      RewriteCond %{SERVER_PORT} ^443$
                      RewriteRule ^robots.txt$ robots_ssl.txt

                      The lines:
                      RewriteEngine on
                      Options +FollowSymlinks

                      Already exist at the top of the htaccess.

                      It has worked for me before but it dos not work on this site.
                      Is the SSL server port different?
                      This doesn't work due to the way that we load balance our servers. In this case, the SSL is on port 80 by default on each server, but the load balancer checks this first, which is why the above does not work.

                      What you will need to do here is set up the SSL for certain pages only:

                      RewriteCond %{ENV:HTTPS} !=on
                      RewriteRule ^(login.php?)$ https://yourdomain/$1 [R=301,L,NC]
                      RewriteCond %{ENV:HTTPS} !=on
                      RewriteRule ^(create_account.php?)$ https://yourdomain/login.php?form=account$1 [R=301,L,NC]

                      This is an example of when going to login.php that it will make it go to the SSL, as with create_account.php. You can then use the following code to make sure that the SSL is not used normally:

                      RewriteEngine On

                      RewriteCond %{ENV:HTTPS} on
                      RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

                      If you have any further questions, I am happy to help.
                      I haven't done any more with this yet but wanted to add it to the mix to get some thoughts from people.

                      Thanks
                      Jonathan Chappell
                      Website Designer
                      SellerDeck Website Designer
                      Actinic to SellerDeck upgrades
                      Graphicz Limited - www.graphicz.co.uk

                      Comment

                      Working...
                      X