http to https into subfolder (.htaccess)

I have a WordPress running on an Apache Server. Now I want to configure the following using .htaccess:

  • Force http to https
  • Redirect requests from (www.)domain.com to domain.com/domaincom/web

So if a user types: http://www.domain.com he will be directed to https://domain.com/domaincom/web but in the browser navigation he will see https://domain.com.

Read More

I already have the following:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTPS} =off
RewriteRule ^ https://%{HTTP_HOST}/domaincom/web/%{REQUEST_URI} [QSA,L,R=301]

But this does not replace the URL. Can you help me?

Related posts

2 comments

  1. Try :

    RewriteEngine on
    
    #Enable https
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
    # if we are not already on /domain/web
    RewriteCond %{REQUEST_URI} !^/domaincom/we [NC]
    #Then rewrite any request to /domaincom/web
    RewriteRule ^(.*)$ /domaincom/web/$1 [NC,L]
    

    The Second condition is important here to prevent rewrite loop error. otherwise without this condition /domaincom/web keeps rewriting to itself.

  2. Web sites behind load balancers or reverse proxies that support HTTP_X_FORWARDED_PROTO can be fixed by adding the following code to the wp-config.php file, above the require_once call:

    if (isset($_SERVER[‘HTTP_X_FORWARDED_PROTO’]) && $_SERVER[‘HTTP_X_FORWARDED_PROTO’] == ‘https’)
    $_SERVER[‘HTTPS’] = ‘on’;

    OR by plugin

    Add into WordPress plugins folder on your website, then activate it in the Plugins admin

    https://gist.github.com/krunalsojitra/b975043933bca9183f57581e45858949

    It is working like

    http://www.exmaple.com/blog/ **to ** https://www.exmaple.com/blog/

    http://www.exmaple.com/ **to ** https://www.exmaple.com/

Comments are closed.