URL redirection going in circles

5 replies
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!

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]
#circles #circular #https #loop #redirection #rewriterule #url
  • Profile picture of the author RobinInTexas
    Did you try

    RewriteCond %{REQUEST_FILENAME}
    instead of %{SCRIPT_FILENAME}


    ...Even if you're on the right track, you'll get run over if you just set there.
    {{ DiscussionBoard.errors[9033391].message }}
    • Profile picture of the author David Beroff
      Originally Posted by RobinInTexas View Post

      Did you try...
      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!
      Put MY voice on YOUR video: AwesomeAmericanAudio.com
      {{ DiscussionBoard.errors[9035291].message }}
  • Profile picture of the author SteveJohnson
    This should work (didn't test it, though)
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} !images [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[9034603].message }}

Trending Topics