URL redirection going in circles

by 5 replies
6
I've done this before successfully, so it confuses me that I'm failing at it now. My goal is to make any attempt at a non- URL redirect to its counterpart except for files in the directory, since those will be used in some emails. Instead, the file below is causing browsers to attempt an infinite loop of redirection, ultimately hitting an error. That behavior could imply that I had forgotten the first termination condition below, except that I hadn't. Thanks in advance for your help!

Code:
RewriteEngine On
RewriteBase /
DirectorySlash On

# Force https: on everything except images: (e.g., for emails)
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} !^/images(/|$)
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,QSA,L]
#programming #circles #circular #https #loop #redirection #rewriterule #url
  • Did you try

    Code:
    RewriteCond %{REQUEST_FILENAME}
    instead of %{SCRIPT_FILENAME}
    • [ 1 ] Thanks
    • [1] reply
    • Thanks, Robin. Even though the spec says that these two are much the same, (with some subtle differences), I did go ahead and try this, to no avail. Thanks, anyway!
  • This should work (didn't test it, though)
    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} !images [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    • [ 1 ] Thanks
    • [1] reply
    • Agreed that it should, Steve, but it doesn't. I just tried this, and it yields the same circular results. Thank you, anyway!!
      • [1] reply

Next Topics on Trending Feed

  • 6

    I've done this before successfully, so it confuses me that I'm failing at it now. My goal is to make any attempt at a non-https URL redirect to its https counterpart except for files in the /images/ directory, since those will be used in some emails. Instead, the .htaccess file below is causing browsers to attempt an infinite loop of redirection, ultimately hitting an ERR_TOO_MANY_REDIRECTS error. That behavior could imply that I had forgotten the first RewriteCond termination condition below, except that I hadn't. Thanks in advance for your help! Code: RewriteEngine On RewriteBase / DirectorySlash On # Force https: on everything except images: (e.g., for emails) RewriteCond %{HTTPS} off RewriteCond %{SCRIPT_FILENAME} !^/images(/|$) RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,QSA,L]