Eu fiz assim:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]
E funciona muito bem.
Estamos tentando redirecionar nosso site de http para https apenas. Tudo o que tentamos no .htaccess resultou em um loop de redirecionamento. Se digitarmos manualmente "https: //" na frente do URL, nossa página retornará jQuery error!
. Então eu suspeito que tem algo a ver com nem todos os recursos solicitados estão sendo solicitados por https?
Nosso arquivo htaccess:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# change rewrite base if not in root
RewriteBase /
# api
RewriteRule ^(api)($|/) - [L]
# index.php
RewriteRule ^index.php$ - [L]
# pass-through
RewriteRule ^(css|js|site)/.*$ - [L]
# redirect errors
ErrorDocument 400 /error/400/
ErrorDocument 401 /error/401/
ErrorDocument 403 /error/403/
ErrorDocument 404 /error/404/
ErrorDocument 500 /error/500/
RewriteRule ^error/(.*)/$ index.php?page=error&eid=$1 [L]
# login
RewriteRule ^login$ login/ [R]
RewriteRule ^login/$ index.php?page=login
# logout
RewriteRule ^logout$ logout/ [R]
RewriteRule ^logout/$ index.php?page=logout
# ip requests
RewriteRule ^request_ip$ request_ip/ [R]
RewriteRule ^request_ip/$ index.php?page=request_ip
# IE fix
RewriteRule ^login/dashboard/$ dashboard/ [R]
RewriteRule ^logout/dashboard/$ dashboard/ [R]
# upgrade
RewriteRule ^upgrade$ upgrade/ [R]
RewriteRule ^upgrade/$ index.php?page=upgrade
# install
RewriteRule ^install$ install/ [R]
RewriteRule ^install/$ index.php?page=install
# dashboard
RewriteRule ^dashboard/$ index.php?page=dashboard
# widgets
RewriteRule ^widgets/(.*)/$ index.php?page=widgets&subpage=$1
# subnets
RewriteRule ^subnets/(.*)/(.*)/ipdetails/(.*)/$ index.php?page=subnets§ion=$1&subnetId=$2&ipaddrid=$3 [L]
RewriteRule ^subnets/(.*)/(.*)/changelog/$ index.php?page=subnets§ion=$1&subnetId=$2&sPage=changelog [L]
RewriteRule ^subnets/(.*)/(.*)/(.*)/$ index.php?page=subnets§ion=$1&subnetId=$2&sPage=$3 [L]
RewriteRule ^subnets/(.*)/(.*)/$ index.php?page=subnets§ion=$1&subnetId=$2 [L]
RewriteRule ^subnets/(.*)/$ index.php?page=subnets§ion=$1 [L]
# folders
RewriteRule ^folder/(.*)/(.*)/$ index.php?page=folder§ion=$1&subnetId=$2 [L]
RewriteRule ^folder/(.*)/$ index.php?page=folder§ion=$1 [L]
# vlans
RewriteRule ^vlan/(.*)/(.*)/$ index.php?page=vlan§ion=$1&vlanId=$2 [L]
# vrfs
RewriteRule ^vrf/(.*)/(.*)/$ index.php?page=vrf§ion=$1&vrfId=$2 [L]
# changelog override
RewriteRule ^tools/changelog/(.*)/(.*)/$ index.php?page=tools&toolsId=changelog&cfilter=$1&climit=$2 [L]
RewriteRule ^tools/changelog/(.*)/$ index.php?page=tools&toolsId=changelog&climit=$1 [L]
# search override
RewriteRule ^tools/search/(.*)$ index.php?page=tools&toolsId=search&ip=$1 [L]
# devices override
RewriteRule ^tools/devices/hosts/(.*)$ index.php?page=tools&toolsId=devices&deviceid=$1 [L]
# tools
RewriteRule ^tools/(.*)/$ index.php?page=tools&toolsId=$1 [L]
RewriteRule ^tools/$ index.php?page=tools&toolsId=showAll [L]
# admin
RewriteRule ^administration/manageSection/sectionChangelog/(.*)/$ index.php?page=administration&adminId=sectionChangelog§ionId=$1 [L]
RewriteRule ^administration/(.*)/$ index.php?page=administration&adminId=$1 [L]
RewriteRule ^administration/$ index.php?page=administration&adminId=showAll [L]
A colocação manual de https no URL (sem modificação no htaccess) produz o seguinte:
Deveserparecidocomoseguinte:
Eu fiz assim:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]
E funciona muito bem.
Tags ssl redirect php .htaccess apache-2.2