Forum Moderators: phranque

Message Too Old, No Replies

Redirecting of addon domain from http to https issue

When addon domain redirects to https it reveals the main domain url

         

lzr0

10:14 am on Feb 27, 2022 (gmt 0)

10+ Year Member



Hi,
I have a shared webhosting with cpanel, which allows to serve additional domains on the same hosting plan. I have main domain (say) main dot com and addon domain (say) addon dot com. The main domain correctly redirects to https. The addon files are placed in the subfolder main dot com /addon, and in the cpanel I accordingly pointed addon.com domain to the above subfolder. When I type in browser's address bar https:// addon dot com it correctly shows this url. My problem is, when I type http:// addon dot com, it redirects to https:/ main dot com /addon. In other words, when it redirects my addon domain from http to https it does not mask the main domain url.
In my htaccess file I have the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^addon\\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.addon.com/$1 [R,L]

Did I do it wrong?

lucy24

6:46 pm on Feb 27, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Where is the other canonicalization redirect--the one that redirects http://example.main to https://example.main ? It has to EITHER be located after the one for example.addon, OR its own conditions have to specify
!example\.addon

Here it sounds as if requests for example.addon are getting picked up by a rule that is only meant for example.main

It's important to remember that all requests travel through the entire (physical) directory structure; they don’t levitate directly into the specified subdirectory. If you have a main/addon setup--as many hosts do--all requests for all addon domains will first see the main domain's htaccess. There are a few ways to get around this problem, but that may be a different thread.

when it redirects my addon domain from http to https it does not mask the main domain url
I’m not sure what you mean by “mask” in this context.

lzr0

8:55 pm on Feb 27, 2022 (gmt 0)

10+ Year Member



Hi, Lucy24,
Where is the other canonicalization redirect--the one that redirects http://example.main to https://example.main ?

I am not sure I understand it. I thought my script in htaccess does this.

I’m not sure what you mean by “mask” in this context.


I meant that although my addon site files are located in subfolder of main domain, the browser should not show the main domain url. In other words, when a browser opens addon site, in address bar I should read just addon .com rather than main .com/addon
The

not2easy

9:53 pm on Feb 27, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Your .htaccess file might do better if each domain folder has it own file to handle its own canonicalization and https rewrite. Don't forgetto specify a 301 redirect because the default (if 301 is not specified) is a 302 (temporary) redirect. That "[R,L]" at the end is producing a 302 response. Using "[R=301,L]" instead will return a 301 response.

Not every server is set up the same way so test after changes. Usually, when you add a .htaccess file to a folder then it does not inherit rewrite rules from the 'main' domain's .htaccess file.

phranque

12:00 am on Feb 28, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



my best guess is that there is a set of mod_dir directives that fire an internal rewrite to /addon/ before the external redirect (with an [L] flag) from http: to https: protocol.

to solve this we will have to see all the mod_dir directives in both directory's .htaccess files.

w3dk

7:07 pm on Feb 28, 2022 (gmt 0)

10+ Year Member Top Contributors Of The Month




RewriteCond %{HTTP_HOST} ^addon\\.com [NC]


Aside: Unless this is just a typo in your post, this condition will never actually match (so the rule is not doing anything). This condition is matching a literal slash ie. "addon\.com", not "addon.com" which is the intention. (You've backslash-escaped the slash, not the dot.)


I meant that although my addon site files are located in subfolder of main domain, the browser should not show the main domain url. In other words, when a browser opens addon site, in address bar I should read just addon .com rather than main .com/addon


Note that .htaccess files work along the filesystem-path, not the URL-path. So, the .htaccess file in the parent directory can still apply here. (Although mod_rewrite directives are not normally inherited by default.) This is assuming the addon domain is pointing directly at this subdirectory - as is usually the case with cPanel.

This is a common issue when addon domains (and subdomains) point to subdirectories of the main domain and are used to host a separate site (with their own config in .htaccess). Conflicts with parent config/.htaccess can occur.

lzr0

7:33 am on Mar 1, 2022 (gmt 0)

10+ Year Member



OK, thank you all for your input