【问题标题】:.htaccess conditional RewriteBase.htaccess 条件 RewriteBase
【发布时间】:2013-08-27 18:16:24
【问题描述】:

以下是.htaccess的一部分:

 <IfModule mod_rewrite.c>
    RewriteCond %{HTTPS} =on    
    #RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R,L]
    RewriteEngine on
    #RewriteBase /~example/    
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
  </IfModule>

当我删除 RewriteBase 之前的评论时,我可以通过虚拟主机提供的共享 SSL 访问我的网站: https://secure.myhost/~example/。但是,当我尝试通过 http://example.com 以非安全方式访问它时,它会导致服务器错误

我的问题是:有没有办法让 .htaccess 有条件地考虑基于 HTTPS 或 HTTP 的 RewriteBase ?

【问题讨论】:

    标签: apache .htaccess cakephp mod-rewrite ssl


    【解决方案1】:

    您的重写规则需要一些重构。用这个替换你的代码:

    Options +FollowSymLinks -MultiViews
    
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteBase /~example/
    
        RewriteCond %{HTTPS} on    
        RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R,L]
    
        RewriteRule (?!webroot/)^(.*)$ webroot/$1 [L,NC]
    </IfModule>
    

    【讨论】:

    • 不幸的是,您的解决方案在尝试通过 http 访问网站时也会导致相同的内部服务器错误。但是,它适用于 https。
    • 它不是 wordpress 应用程序。这是一个 cakephp 应用程序。我在public_html根目录的.htaccess中使用了这段代码。
    • 不,我没有任何 VirtualHost 条目。
    • 好的,在 Cakephp 中有没有你定义基本 URL 的地方有https://?某处 https 正在执行中。
    • 真的,我不知道!但是,我将添加 cakephp 标记以查看任何其他帮助。非常感谢。
    猜你喜欢
    • 2012-03-14
    • 1970-01-01
    • 2013-05-17
    • 2020-06-21
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 1970-01-01
    • 2011-01-26
    相关资源
    最近更新 更多