4

I've never worked with Apache, so I'm a completely newbie.

I have a multihosting account on a provider website, where 3 domain are used. I want to force https connection on a domain, let's say example.com, which is not the main domain of the hosting plan. What I did is to add an .htaccess file in the path examplecom/public_html, the folder where there are all the file of the website. In the .htaccess I have copy-pasted this strings from the provider guide:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301]

The website works correctly if I go to a page with an non-empty URI, but it doesn't on the main page. In example: http://example.com/anypage is correctly redirected to https://www.example.com/anypage, while http://example.com/ is redirected to https://www.example.com/public_html, and can't understand why.

  • Do you have any other directives in your .htaccess file? Is examplecom/public_html the document root of this domain? How is this additional domain configured? Where does this point to in relation to the main domain? – MrWhite Oct 3 at 0:14
3

It looks like you might have a conflict with existing directives, however, you can try changing your existing directives to see if it makes a difference:

RewriteEngine On

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://www.example.com/$1 [L,R=301]

Providing the .htaccess file is located in the examplecom/public_html directory then the captured backreference ($1) should only contain anything that comes after this (if anything). Whereas the REQUEST_URI server variable always contains the full URL-path.

The RewriteBase directive is superfluous here since you are using an absolute URL in the RewriteRule substitution.

You will need to clear your browser cache before testing as the erroneous 301 will likely have been cached. Test with 302 (temporary) redirects to avoid caching issues.

| improve this answer | |
  • 1
    The solution you suggest worked perfectly! Thanks – arna1998 Oct 3 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.