Question

I have two domains pointing to the same website, domain A and domain B. I want:

  • Domain A to be accessible via HTTP (works fine out of the box)
  • Domain B to redirect all requests to HTTPS. Basically if you type in http://domainb.com/somepage to redirect to http*s*://domainb.com/somepage. I would prefer to have this done via htaccess file.

I tried many solutions and I always get into redirection loop. Eg. I tried this:

RewriteCond     %{SERVER_NAME} ^www\.domainb\.com$ [NC]
RewriteCond %{HTTPS} off
RewriteRule     ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
....
rest of the standard typo3 htaccess commands. 

My code was after typo3 be redirection part and before "Main URL rewriting" part in the htaccess file. With code above I'm redirected to https but then "redirection loop" error is shown.

Any help is highly appreciated.

Was it helpful?

Solution

This works for me :)

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

I include this code right after this line with RewriteEngine On.

OTHER TIPS

Try this:

RewriteRule ^http://www\.domainb\.com/(.*) https://www\.domainb\.com/$1 [R=301,L]

The only solution that worked for me was the following one:

RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top