【问题标题】:How to fix htaccess ssl https redirect?如何修复 htaccess ssl https 重定向?
【发布时间】:2015-08-15 17:25:56
【问题描述】:

我使用过搜索和 Google,但似乎找不到解决方案。我正在尝试将其重定向到 HTTPS,但遇到了一些问题。我不断得到:

ERR_TOO_MANY_REDIRECTS

下面是我的 htaccess 文件。我宁愿这样,而不是向每个 html 代码添加代码。我已经尝试了所有方法,但无法弄清楚。

# Multiple Environment config
# Set this to development, staging or production
# SetEnv PYRO_ENV production
<IfModule mod_rewrite.c>

    # Make sure directory listing is disabled
    Options +FollowSymLinks -Indexes
    # disable the Apache MultiViews directive if it is enabled on the server. It plays havoc with URL rewriting
    Options -MultiViews
    RewriteEngine on
        RewriteCond %{HTTPS} !=on
        RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RedirectMatch 403 ^/.*/(system/cms/cache|system/codeigniter|system/cms/config|system/cms/logs|\.git|\.hg).*$

    # Send request via index.php (again, not if its a real file or folder)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    <IfModule mod_php5.c>
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>

    <IfModule !mod_php5.c>
        RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>

</IfModule>

编辑:问题解决了下面的代码工作。请锁定

RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://mydomain(dot)com/$1 [R,L]

【问题讨论】:

标签: php .htaccess redirect ssl pyrocms


【解决方案1】:

试试下面的代码,它应该可以工作:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks -Indexes
    Options -MultiViews

    RewriteEngine On
    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RedirectMatch 403 ^/.*/(system/cms/cache|system/codeigniter|system/cms/config|system/cms/logs|\.git|\.hg).*$

    # Send request via index.php (again, not if its a real file or folder)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

【讨论】:

  • 您好,感谢您的回复,我尝试了您给我的这段代码,但仍然遇到完全相同的错误
  • @user3732612 您可以尝试仅放置 http 到 https 相关的重定向并删除所有其他部分。并逐渐继续添加其他规则。这样你就可以找到有问题的线路。
  • 好吧,如果我单独使用 Rewritecond 它可以工作,但是我的 pyrocms 错误没有其余部分。
  • 我检查了代码,如果我删除了除 https 重定向之外的所有内容,我会得到同样的错误,但如果我保留所有内容并删除重定向,我的网站加载时没有 SSL 重定向
  • 你还有什么其他的东西迫使你的网站到http吗?看起来是因为您的网站可以正常使用 http。但是 https 它有重定向循环。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-30
  • 1970-01-01
  • 2012-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多