1

We are trying to redirect our site from http to https only. Everything we have tried in .htaccess has resulted in a redirect loop. If we manually type the "https://" in front of the url, our page returns jQuery error!. So I suspect it has something to do with not all the requested resources are being requested over https?

Our htaccess file:

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&section=$1&subnetId=$2&ipaddrid=$3 [L]
RewriteRule ^subnets/(.*)/(.*)/changelog/$ index.php?page=subnets&section=$1&subnetId=$2&sPage=changelog [L]
RewriteRule ^subnets/(.*)/(.*)/(.*)/$ index.php?page=subnets&section=$1&subnetId=$2&sPage=$3 [L]
RewriteRule ^subnets/(.*)/(.*)/$ index.php?page=subnets&section=$1&subnetId=$2 [L]
RewriteRule ^subnets/(.*)/$ index.php?page=subnets&section=$1 [L]

# folders
RewriteRule ^folder/(.*)/(.*)/$ index.php?page=folder&section=$1&subnetId=$2 [L]
RewriteRule ^folder/(.*)/$ index.php?page=folder&section=$1 [L]

# vlans
RewriteRule ^vlan/(.*)/(.*)/$ index.php?page=vlan&section=$1&vlanId=$2 [L]

# vrfs
RewriteRule ^vrf/(.*)/(.*)/$ index.php?page=vrf&section=$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&sectionId=$1 [L]
RewriteRule ^administration/(.*)/$ index.php?page=administration&adminId=$1 [L]
RewriteRule ^administration/$ index.php?page=administration&adminId=showAll [L]

Manually putting https in the url (with no modification to htaccess) produces the following:

enter image description here

It should look like the following:

enter image description here

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
techfutures
  • 31
  • 1
  • 4
  • 1
    You don't have a RewriteCond in that entire block. I would say that's probably related. You also don't mention "https" in that entire block; so I am curious as to how you think this will rewrite to https. – Peter Jun 15 '14 at 06:47
  • Show at least what you tried and what the results were. – Michael Hampton Jun 15 '14 at 12:06
  • I used the following two lines in the .htaccess i posted above: RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] result was , "This webpage has a redirect loop" – techfutures Jun 16 '14 at 07:11
  • original question updated with screenshots and htaccess that caused issue, see lines 2 and 3 – techfutures Jun 16 '14 at 07:21

1 Answers1

1

I did it like this:

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]

And it works just fine.