My app is hosted on heroku, and I am using Cakephp API. I want it to be redirect to https://www. and enforcing the www. subdomain.
And, they have two domains point to the same app.
I have the follow code, in the /app/.htaccess
RewriteEngine on
RewriteBase /
#apply if no https
RewriteCond %{HTTPS} off
#Ignore when is local env or any staging env
RewriteCond %{HTTP_HOST} !^local(.*) [NC]
RewriteCond %{HTTP_HOST} !^(.*)heroku(.*) [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
#apply if https
RewriteCond %{HTTPS} on
#Ignore when is local env or any staging env or subdoamin is www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^local(.*) [NC]
RewriteCond %{HTTP_HOST} !^(.*)heroku(.*) [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
#default from cakephp
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
I have the follow code, in the /app/webroot/.htaccess
RewriteEngine On
RewriteBase /
#redirect any request from .poa.br to .com.br
RewriteCond %{HTTP_HOST} ^(.*)example\.poa\.br$ [NC]
RewriteRule ^(.*)$ https://www.example.com.br/$1 [NE,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
But it doesn't work. Just the follows requests are redirect to https://www.example.com.br:
https://www.example.com.br
https://www.example.poa.br
http://www.example.poa.br
This option go to domain, but without https prefix.
http://www.example.com.br
The other options doesn't work (return DNS_PROBE_FINISHED_NXDOMAIN):
https://example.com.br
http://example.com.br
https://example.poa.br
http://example.poa.br