Add HTTPS to a website that isn’t at the root

Asked

Viewed 34 times

1

I have a site that he is not at the root, when entering it he adds/portal in front of the link because it is divided into folders inside the root, when accessing the /portal he goes to the index of the site and when accessing /news/nXX he goes to a newsletter of the site. Usually to add the HTTPS to the site I go to the htaccess file and put the following text:

Rewriteengine On Rewritecond %{HTTPS} off Rewriterule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

However, as I was not the one who made this site, in his htaccess already has a lot of codes (which redirect to the /portal when accessing the root), I tried to add but was not successful.

1 answer

1

I figured it out myself, but I’ll leave the solution here for whoever’s going through what I’ve been through:

I should be going to htaccess inside the portal folder and not inside the root, I went there on it and there was already the following code:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /portal/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /portal/index.php [L]
</IfModule>

# END WordPress

# php -- BEGIN cPanel-generated handler, do not edit
# NOTE this account's php is controlled via FPM and the vhost, this is a place holder.
# Do not edit. This next line is to support the cPanel php wrapper (php_cli).
# AddType application/x-httpd-ea-php56 .php .phtml
# php -- END cPanel-generated handler, do not edit

then I just added the following lines above the line :

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

and in the end it was like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /portal/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /portal/index.php [L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# END WordPress

# php -- BEGIN cPanel-generated handler, do not edit
# NOTE this account's php is controlled via FPM and the vhost, this is a place holder.
# Do not edit. This next line is to support the cPanel php wrapper (php_cli).
# AddType application/x-httpd-ea-php56 .php .phtml
# php -- END cPanel-generated handler, do not edit

Browser other questions tagged

You are not signed in. Login or sign up in order to post.