doudai8783 2018-06-12 02:08 采纳率: 100%
浏览 88
已采纳

在SocialEngine 4.2.9中将htaccess修改为https重定向后,重定向过多问题[重定向循环]

Recently I have installed the ssl certificate for our domain. And as part of https secure redirection, changed the htaccess to redirect to https. It works fine with the home page. But when I am login as a user or as an admin, the redirection fails and getting a message like too many redirects and page loading is failed due to redirect looping back and forth between https and http. Please help me to solve this issue.

Please find the current htaccess file that I am using

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On

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

  RewriteRule ^(blog)($|/) - [L]

  # Get rid of index.php
  RewriteCond %{REQUEST_URI} /index\.php
  RewriteRule (.*) index.php?rewrite=2 [L,QSA]

  # Rewrite all directory-looking urls
  RewriteCond %{REQUEST_URI} /$
  RewriteRule (.*) index.php?rewrite=1 [L,QSA]

  # Try to route missing files
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} public\/ [OR]
  RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
  RewriteRule . - [L]

  # If the file doesn't exist, rewrite to index
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]

</IfModule>

When I access https://www.flatparty.com it works fine. But once I logged in gets the redirection issue.

  • 写回答

2条回答 默认 最新

  • doumou1864 2018-06-28 05:25
    关注

    Finally I got the fix for the issue !!. It was not the issue with .htaccess content, it was the issue with the server code. The following code was the reason for the redirect loop issue.

    $host = $_SERVER['HTTP_HOST'];
    $request_uri = $_SERVER['REQUEST_URI'];
    $good_url = "http://" . $host . $request_uri;
    
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: $good_url");
    

    The .htaccess code is working fine and whenever htaccess redirects url to https and the above mentioned code gets redirected to http and eventually it leads to an infinite loop and request will never completes.

    Thanks for the help and suggestions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?