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
.
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?
Try :
The Second condition is important here to prevent rewrite loop error. otherwise without this condition /domaincom/web keeps rewriting to itself.
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/