How To Redirect to HTTPS with .htaccess

Поделиться
HTML-код
  • Опубликовано: 26 авг 2024
  • Learn how to redirect your website traffic from HTTP to HTTPS with the .htacces file. If you have ssh or FTP access to your Apache web server, you can modify your .htaccess file with a permanent 301 redirect to send all traffic to the HTTPS version of your website.
    Code snippet:
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ example.com/$1 [R=301,L,NE]
    Header always set Content-Security-Policy "upgrade-insecure-requests;"
    Find more at tonyteaches.tech
    Check out my vlog channel ‪@TonyFlorida‬
    #https #htaccess #apache

Комментарии • 34

  • @antidotejack2771
    @antidotejack2771 3 месяца назад

    I've just got my first VPS and you've been an angel to me.

  • @manfredthiele5282
    @manfredthiele5282 Год назад +2

    Thank you, works now....

  • @devmehedi5455
    @devmehedi5455 3 года назад +1

    wow. you are great . i was using the code and i am successful . thank you so much . love from Bangladesh .

  • @axeltoure2055
    @axeltoure2055 2 года назад

    merci beaucoup depuis la côte d'ivoire

  • @foreign-livingtheamericand8782

    nice tip, hey i have a question.... the AddType, is that the full path from the root folder? also, is this for all files except php?

  • @rankandrent360
    @rankandrent360 Год назад

    Man THANK YOU

  • @ravi-gadhiya
    @ravi-gadhiya 4 года назад

    I was using filezilla and vscode to edit htaccess. thanks tony

  • @dodypod9334
    @dodypod9334 Год назад

    for me still not working, any suggestions?

  • @wzafar77
    @wzafar77 3 года назад +1

    After Using the code my site goes like below... This creates two 301 redirects... Can someone tell me what's happening?
    www.example.com
    301 Moved Permanently
    >
    www.example.com/
    301 Moved Permanently
    >
    example.com/
    200 OK

  • @SamadCrypto
    @SamadCrypto Год назад

    it is not work for me in infinityfree

  • @justinchildressofficial
    @justinchildressofficial 2 года назад

    I got a notification in Google Analytics saying that my property is getting traffic from multiple host names (www and non www urls). This happened after I switched hosting from Bluehost to Cloudways. The solution Google gives is to create a 301 redirect in the .htaccess file. Any thoughts on why this happened and do you happen to know how to add this particular 301 redirect? Thanks Tony!

    • @TonyTeachesTech
      @TonyTeachesTech  2 года назад

      The way Google "sees" websites is weird because it thinks that the following URLs are all different websites!
      - example.com
      - www.example.com
      - example.com
      - www.example.com
      I set up all my websites to have the URLs redirect to example.com
      Google's suggestion is valid and this video is exactly what you need to do. LMK if you have issues Jusin.

  • @ronak920
    @ronak920 4 года назад

    I think the redirect through Cloudflare dns is faster. What do you think ?

    • @TonyTeachesTech
      @TonyTeachesTech  4 года назад

      Depends on a lot of factors, but the best way to know for sure would be to test it out

  • @user-cj2kj8hi3j
    @user-cj2kj8hi3j Год назад

    How about. HTTPS to HTTP Sir? revert back

  • @amosonyoutube
    @amosonyoutube 3 года назад

    thanks

  • @noticedcloud3488
    @noticedcloud3488 Год назад

    sorry the site says the page has redirected you too many times.

  • @kshirodhati4093
    @kshirodhati4093 Год назад

    Have to put .htaccess file in every directory ??

    • @Adrian-1712
      @Adrian-1712 Месяц назад

      You make only one .htacces file in you main directory. You‘ve just waited one year with this one.

  • @howyadoing9103
    @howyadoing9103 3 года назад

    Well, that didn't work. made the site inaccessible until I deleted the snippet.

    • @TonyTeachesTech
      @TonyTeachesTech  3 года назад

      Sorry to hear that. Not sure why that's the case

  • @muhaasibjamaal2932
    @muhaasibjamaal2932 3 года назад

    What is it that we need to learn to write instructions such as these to modify how the web server operates? Thanks

    • @TonyTeachesTech
      @TonyTeachesTech  3 года назад

      These are just configuration files for the web server (Apache and Nginx for example)

  • @howyadoing9103
    @howyadoing9103 3 года назад

    Here is the file. I want to redirect it to myfile.com
    # BEGIN WordPress
    # The directives (lines) between "BEGIN WordPress" and "END WordPress" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress
    Please advise