Why would .htaccess rewrite rules that work perfectly fine elsewhere produce redirect loops? -
i'm trying force non-www + https in .htaccess on aws ec2 instance.
while there abundance of apparently working solutions right here on stackoverflow, of produce redirect loops me.
i redirect loop when try rule:
rewriteengine on #rewritecond %{http_host} ^(www\.)(.+) [or] #rewritecond %{https} off #rewritecond %{http_host} ^(www\.)?(.+) #rewriterule ^ https://%2%{request_uri} [r=301,l]
(via force non-www , https via htaccess)
same one:
rewriteengine on #rewritecond %{http_host} !^domain.com$ [nc] #rewriterule ^(.*)$ https://domain.com/$1 [l,r=301] #rewritecond %{https} off #rewriterule ^(.*)$ https://domain.com/$1 [r,l]
both seem work respective op, , indicated of comments, work others too.
i have following virtualhosts set in httpd.conf
:
namevirtualhost *:80 listen 8443 namevirtualhost *:8443 <virtualhost *:80 *:8443> serveradmin webmaster@domain.com documentroot /var/www/domain.com servername domain.com serveralias *.domain.com errorlog logs/domain.com-error_log customlog logs/domain.com-access_log common </virtualhost>
for context: :8443 port receives traffic aws elb (load balancer) routes :443 ssl requests particular port, because ssl certificate installed on load balancer itself.
what issue redirect loops?
behind load balancer have handle things differently. won't checking https
in normal way because of ssl offloading lb. need check x-forwarded-proto
try these rules , see how work.
rewriteengine on rewritecond %{http:x-forwarded-proto} !https [or] rewritecond %{http_host} ^www\. [nc] rewritecond %{server_name} ^(www\.)?(.*)$ [nc] rewriterule ^.*$ https://%2%{request_uri} [r=301,l]
Comments
Post a Comment