• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer
Old Gamess

Old Gamess

Free Games and Software Download

  • Home
  • Software
    • Antivirus
    • MS Office
    • ISO Tool
  • Windows OS
  • Mac OS
  • PC Games
  • Emulators
    • PlayStation 1 Emulator
    • PlayStation 2 Emulator
    • PlayStation 3 Emulator
    • Nintendo 64 Emulator
    • GameCube Emulator
  • Android
  • Code
  • Blog

Code to redirect non https to https

January 18, 2023 by Admin Leave a Comment

To redirect all non-HTTPS requests to HTTPS, you can use the .htaccess file on an Apache web server. Here is an example of the code that can be used to accomplish this:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

This code uses the mod_rewrite module of Apache to check if the current connection is not using HTTPS, and if so, it redirects the user to the same URL, but using HTTPS. The [R=301,L] flag tells Apache to use a HTTP status code of 301 (permanent redirect) and stop processing any further rules.

You can also check if the server variable HTTP_X_FORWARDED_PROTO is set to http and redirect in that case:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This code uses the mod_rewrite module of Apache to check if the current connection is not using HTTPS by checking the value of the “X-Forwarded-Proto” header and redirects the user to the same URL, but using HTTPS.

You should be careful with the use of .htaccess files as it can cause errors or security issues if not properly configured. It’s also important to have a valid SSL certificate installed on your server to have a successful redirect to https.

Share this:

  • Twitter
  • Facebook

Related

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Subscribe my YouTube Channel

Popular Posts

  • GTA Vice City Download For PC
  • GTA San Andreas Download For PC
  • Windows XP ISO Download
  • Top 10 Anime Websites to Watch Free Anime Online

Follow Us

  • Facebook
  • YouTube

Footer

HOME  |   ABOUT  |  DMCA  |  DISCLAIMER  |  PRIVACY  |  CONTACT
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright © 2023 ยท [oldgamess.com]