SEO-friendly HTACCESS 301 redirect for non-www to www PLUS .php to non-.php PLUS http to htps [duplicate]










0















This question already has an answer here:



  • htaccess redirect to https://www

    13 answers



I have a custom build non-CMS site on PHP.



The way my current .htaccess is setup is to allow me to use the urls without ".php" part and to 301 redirect all non www requests to www:



RewriteEngine On
RewriteCond %HTTP_HOST ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ $1.php [L,QSA]


Now we are switching to HTTPS.



How do I get a proper SEO-friendly redirect from http:// to https:// in .htaccess?



I've tried replacing third string with



RewriteRule (.*) https://www.example.com/$1 [R=301,L]


but it doesn't do the trick...



Also, optionally, is there a way to set up a 301 redirect for .php request to redirect to non-.php variant? Although it looks like it means to redirect to same exact page, not sure if it will be SEO-safe to do it or maybe it will even result in a redirect loop?










share|improve this question















marked as duplicate by Machavity php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 11 at 22:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    0















    This question already has an answer here:



    • htaccess redirect to https://www

      13 answers



    I have a custom build non-CMS site on PHP.



    The way my current .htaccess is setup is to allow me to use the urls without ".php" part and to 301 redirect all non www requests to www:



    RewriteEngine On
    RewriteCond %HTTP_HOST ^example.com
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    RewriteCond %REQUEST_FILENAME !-f
    RewriteCond %REQUEST_FILENAME !-d
    RewriteRule ^(.*)$ $1.php [L,QSA]


    Now we are switching to HTTPS.



    How do I get a proper SEO-friendly redirect from http:// to https:// in .htaccess?



    I've tried replacing third string with



    RewriteRule (.*) https://www.example.com/$1 [R=301,L]


    but it doesn't do the trick...



    Also, optionally, is there a way to set up a 301 redirect for .php request to redirect to non-.php variant? Although it looks like it means to redirect to same exact page, not sure if it will be SEO-safe to do it or maybe it will even result in a redirect loop?










    share|improve this question















    marked as duplicate by Machavity php
    Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Nov 11 at 22:37


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      0












      0








      0








      This question already has an answer here:



      • htaccess redirect to https://www

        13 answers



      I have a custom build non-CMS site on PHP.



      The way my current .htaccess is setup is to allow me to use the urls without ".php" part and to 301 redirect all non www requests to www:



      RewriteEngine On
      RewriteCond %HTTP_HOST ^example.com
      RewriteRule (.*) http://www.example.com/$1 [R=301,L]
      RewriteCond %REQUEST_FILENAME !-f
      RewriteCond %REQUEST_FILENAME !-d
      RewriteRule ^(.*)$ $1.php [L,QSA]


      Now we are switching to HTTPS.



      How do I get a proper SEO-friendly redirect from http:// to https:// in .htaccess?



      I've tried replacing third string with



      RewriteRule (.*) https://www.example.com/$1 [R=301,L]


      but it doesn't do the trick...



      Also, optionally, is there a way to set up a 301 redirect for .php request to redirect to non-.php variant? Although it looks like it means to redirect to same exact page, not sure if it will be SEO-safe to do it or maybe it will even result in a redirect loop?










      share|improve this question
















      This question already has an answer here:



      • htaccess redirect to https://www

        13 answers



      I have a custom build non-CMS site on PHP.



      The way my current .htaccess is setup is to allow me to use the urls without ".php" part and to 301 redirect all non www requests to www:



      RewriteEngine On
      RewriteCond %HTTP_HOST ^example.com
      RewriteRule (.*) http://www.example.com/$1 [R=301,L]
      RewriteCond %REQUEST_FILENAME !-f
      RewriteCond %REQUEST_FILENAME !-d
      RewriteRule ^(.*)$ $1.php [L,QSA]


      Now we are switching to HTTPS.



      How do I get a proper SEO-friendly redirect from http:// to https:// in .htaccess?



      I've tried replacing third string with



      RewriteRule (.*) https://www.example.com/$1 [R=301,L]


      but it doesn't do the trick...



      Also, optionally, is there a way to set up a 301 redirect for .php request to redirect to non-.php variant? Although it looks like it means to redirect to same exact page, not sure if it will be SEO-safe to do it or maybe it will even result in a redirect loop?





      This question already has an answer here:



      • htaccess redirect to https://www

        13 answers







      php apache .htaccess redirect seo






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 16:44

























      asked Nov 11 at 16:23









      Acidon

      50021330




      50021330




      marked as duplicate by Machavity php
      Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Nov 11 at 22:37


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Machavity php
      Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Nov 11 at 22:37


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You can use the following htaccess rules (just replace example.com with yourdomain.com in the second RewriteCond)



          RewriteEngine On


          #301 redirect from http to https + non-www to www
          RewriteCond ℅HTTPS off [OR]
          RewriteCond ℅HTTP_HOST ^example.com$ [NC]
          RewriteCond ℅HTTP_HOST (?:www.)?(.+)$
          RewriteRule ^ https://www.℅1℅REQUEST_URI [NE,L,R]

          #remove .php extension
          #redirect to remove .php from URLs
          RewriteCond ℅THE_REQUEST /(.+).php [NC]
          RewriteRule ^ /℅1 [L,R=301]
          #handle extension less php URLs
          RewriteCond ℅REQUEST_FILENAME.php -f
          RewriteRule ^(.+)/?$ /$1.php [L]





          share|improve this answer




















          • I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
            – Acidon
            Nov 11 at 17:47










          • actually even worse - it is redirects all the pages to root domain...
            – Acidon
            Nov 11 at 17:49










          • @Acidon Try cleaning your browser cache.
            – starkeen
            Nov 11 at 18:22

















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can use the following htaccess rules (just replace example.com with yourdomain.com in the second RewriteCond)



          RewriteEngine On


          #301 redirect from http to https + non-www to www
          RewriteCond ℅HTTPS off [OR]
          RewriteCond ℅HTTP_HOST ^example.com$ [NC]
          RewriteCond ℅HTTP_HOST (?:www.)?(.+)$
          RewriteRule ^ https://www.℅1℅REQUEST_URI [NE,L,R]

          #remove .php extension
          #redirect to remove .php from URLs
          RewriteCond ℅THE_REQUEST /(.+).php [NC]
          RewriteRule ^ /℅1 [L,R=301]
          #handle extension less php URLs
          RewriteCond ℅REQUEST_FILENAME.php -f
          RewriteRule ^(.+)/?$ /$1.php [L]





          share|improve this answer




















          • I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
            – Acidon
            Nov 11 at 17:47










          • actually even worse - it is redirects all the pages to root domain...
            – Acidon
            Nov 11 at 17:49










          • @Acidon Try cleaning your browser cache.
            – starkeen
            Nov 11 at 18:22















          0














          You can use the following htaccess rules (just replace example.com with yourdomain.com in the second RewriteCond)



          RewriteEngine On


          #301 redirect from http to https + non-www to www
          RewriteCond ℅HTTPS off [OR]
          RewriteCond ℅HTTP_HOST ^example.com$ [NC]
          RewriteCond ℅HTTP_HOST (?:www.)?(.+)$
          RewriteRule ^ https://www.℅1℅REQUEST_URI [NE,L,R]

          #remove .php extension
          #redirect to remove .php from URLs
          RewriteCond ℅THE_REQUEST /(.+).php [NC]
          RewriteRule ^ /℅1 [L,R=301]
          #handle extension less php URLs
          RewriteCond ℅REQUEST_FILENAME.php -f
          RewriteRule ^(.+)/?$ /$1.php [L]





          share|improve this answer




















          • I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
            – Acidon
            Nov 11 at 17:47










          • actually even worse - it is redirects all the pages to root domain...
            – Acidon
            Nov 11 at 17:49










          • @Acidon Try cleaning your browser cache.
            – starkeen
            Nov 11 at 18:22













          0












          0








          0






          You can use the following htaccess rules (just replace example.com with yourdomain.com in the second RewriteCond)



          RewriteEngine On


          #301 redirect from http to https + non-www to www
          RewriteCond ℅HTTPS off [OR]
          RewriteCond ℅HTTP_HOST ^example.com$ [NC]
          RewriteCond ℅HTTP_HOST (?:www.)?(.+)$
          RewriteRule ^ https://www.℅1℅REQUEST_URI [NE,L,R]

          #remove .php extension
          #redirect to remove .php from URLs
          RewriteCond ℅THE_REQUEST /(.+).php [NC]
          RewriteRule ^ /℅1 [L,R=301]
          #handle extension less php URLs
          RewriteCond ℅REQUEST_FILENAME.php -f
          RewriteRule ^(.+)/?$ /$1.php [L]





          share|improve this answer












          You can use the following htaccess rules (just replace example.com with yourdomain.com in the second RewriteCond)



          RewriteEngine On


          #301 redirect from http to https + non-www to www
          RewriteCond ℅HTTPS off [OR]
          RewriteCond ℅HTTP_HOST ^example.com$ [NC]
          RewriteCond ℅HTTP_HOST (?:www.)?(.+)$
          RewriteRule ^ https://www.℅1℅REQUEST_URI [NE,L,R]

          #remove .php extension
          #redirect to remove .php from URLs
          RewriteCond ℅THE_REQUEST /(.+).php [NC]
          RewriteRule ^ /℅1 [L,R=301]
          #handle extension less php URLs
          RewriteCond ℅REQUEST_FILENAME.php -f
          RewriteRule ^(.+)/?$ /$1.php [L]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 17:19









          starkeen

          29.8k145777




          29.8k145777











          • I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
            – Acidon
            Nov 11 at 17:47










          • actually even worse - it is redirects all the pages to root domain...
            – Acidon
            Nov 11 at 17:49










          • @Acidon Try cleaning your browser cache.
            – starkeen
            Nov 11 at 18:22
















          • I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
            – Acidon
            Nov 11 at 17:47










          • actually even worse - it is redirects all the pages to root domain...
            – Acidon
            Nov 11 at 17:49










          • @Acidon Try cleaning your browser cache.
            – starkeen
            Nov 11 at 18:22















          I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
          – Acidon
          Nov 11 at 17:47




          I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
          – Acidon
          Nov 11 at 17:47












          actually even worse - it is redirects all the pages to root domain...
          – Acidon
          Nov 11 at 17:49




          actually even worse - it is redirects all the pages to root domain...
          – Acidon
          Nov 11 at 17:49












          @Acidon Try cleaning your browser cache.
          – starkeen
          Nov 11 at 18:22




          @Acidon Try cleaning your browser cache.
          – starkeen
          Nov 11 at 18:22



          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo