我的應用託管在heroku上,並且我正在使用Cakephp API。我希望它重定向到https://www。並執行www。子域。如何使用.htacces和cakephp將域名從http重定向到https
而且,他們有兩個域指向同一個應用程序。
我有如下代碼,在/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]
我有如下代碼,在/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]
但它不」工作。就在如下請求重定向到https://www.example.com.br:
https://www.example.com.br
https://www.example.poa.br
http://www.example.poa.br
此選項去域,但沒有HTTPS前綴。
http://www.example.com.br
其他選項不起作用(返程DNS_PROBE_FINISHED_NXDOMAIN):
https://example.com.br
http://example.com.br
https://example.poa.br
http://example.poa.br
嗨Konjesh!它沒有工作。 我相信重寫模塊已打開,因爲我在測試中創建了一些循環。 –
您的建議結果與我的代碼相同。 –