skip to Main Content

Currently I redirect all http users (www or non-www) of upscfever.com to http://upscfever.com/upsc-fever/index.html

using

RewriteEngine on

RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.upscfever.com$
RewriteRule ^/?$ "http://upscfever.com/upsc-fever/index.html" [R=301,L]

Now I want all users to shift to https so I modified as follows:

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.upscfever.com$
RewriteRule ^/?$ "https://upscfever.com/upsc-fever/index.html" [R=301,L]

So that all who type upscfever.com OR www.upscfever.com should go to
https://upscfever.com/upsc-fever/index.html – instead

Plus all links should be https. But its not working I get Page not found.

5

Answers


  1. Your server has to setup the https first, depend on hosting vendor, if your hosting is vps you need to setup https for apache, install cert also.

    You can find some instruction like this:

    https://manual.seafile.com/deploy/https_with_apache.html

    https://www.digicert.com/csr-ssl-installation/apache-openssl.htm

    Login or Signup to reply.
  2. I think you want to make 3 different changes:

    1. Change your .htaccess file to redirect requests to root to your custom index irrespective of the HTTPS or HTTP for the original request
    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.upscfever.com$
    RewriteRule ^/?$ "https://%{SERVER_NAME}/upsc-fever/index.html" [R,L]
    

    There is no R=301 part here because I’m not sure it is really wise to make permanent such a redirect to an obscure inner URL.

    1. Redirect all other non-HTTPS requests to HTTPS (preserving the rest of the URL):
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.upscfever.com$
    
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
    

    Making this redirect permanent seems pretty safe.

    1. Change all internal links in all of your HTML pages (or whatever backend generates them) to use protocol-relative // prefix or explicitly https:// instead of current http://. Preserve the protocol for the external links as is.

    As for troubleshooting, you may use the Network tab of the Chrome DevTools (F12) to see exact server reply (note: enabling “Preserve log” and “Disable cache” flags is useful in such context)

    Chrome DevTools

    Login or Signup to reply.
  3. You can do that using a single rule as follows in your site root .htaccess:

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^(?:www.)?upscfever.com$ [NC]
    RewriteRule ^/?$ /upsc-fever/index.html [R=301,L]
    

    This will redirect both http and https URLs.

    Login or Signup to reply.
  4. You may try something like this:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !=""
    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
    Login or Signup to reply.
  5. I hope below code will do the work for you

    RewriteEngine On 
    RewriteCond %{HTTPS}  !=on 
    RewriteRule ^/?(.*) https://famebooking.net/$1 [R,L] 
    

    just simply add above code in .htaccess below authorization header condition is written under RewriteEngine On

    Let me know if that helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search