代码之家  ›  专栏  ›  技术社区  ›  dell116

.htaccess 301将所有https重定向到http,一页除外

  •  12
  • dell116  · 技术社区  · 16 年前

    以下是我当前在.htaccess文件中的代码:

    Options +FollowSymLinks 
    RewriteEngine on
    RewriteBase / 
    RewriteCond %{HTTP_HOST} ^example.com [NC] 
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    
    RewriteEngine On
    RewriteCond %{HTTPS} on
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    1. 将“example.com”的所有实例重定向到“www.example.com”
    2. 重定向“”的所有实例 https //www.example.com“to” http http://www.example.com“ 除1页外 !!!! (如果有问题,该页面的文件名为payments.php)

    我上面的代码可以工作,但是对于我需要使用https的1页,它正在将url重写为http。这一页必须是https。

    谢谢

    4 回复  |  直到 16 年前
        1
  •  10
  •   St.Woland    16 年前

    Apache/2.2.6(Win32)mod_ssl/2.2.8 OpenSSL/0.9.8g PHP/5.2.6

    我已经在本地进行了测试,所有用例似乎都运行良好。如果您还有其他问题,请随时提问。

    # Rewrite Rules for example.com
    RewriteEngine On
    RewriteBase /
    
    # Redirect from example.com to www.example.com
    RewriteCond %{HTTP_HOST} ^example\.com [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    
    # Turn SSL on for payments
    RewriteCond %{HTTPS} off
    RewriteCond %{SCRIPT_FILENAME} \/payments\.php [NC]
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
    
    # Turn SSL off everything but payments
    RewriteCond %{HTTPS} on
    RewriteCond %{SCRIPT_FILENAME} !\/payments\.php [NC]
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
    

    当用户从任何位置导航时 翻页 对任何人 https 页 万维网

    例如(是=接受证书的请求,否-相反):

    1) https://www.asdf.com/payments.php - YES (www.asdf.com)
    2) http://www.asdf.com/phpinfo.php - NO
    3) https://asdf.com/phpinfo.php - YES (asdf.com)
    4) https://www.asdf.com/phpinfo.php - NO
    

    我试图在.htaccess中重新排序规则,但没有成功。如果有人能找到更好的解决方案,我们将不胜感激。

        2
  •  5
  •   jspcal    16 年前

    RewriteCond %{REQUEST_URI} !^/?payments\.php
    
        3
  •  0
  •   Jayapal Chandran    16 年前

    这是一篇很好的文章,它似乎正确地重定向到http,但我想要下面这样的东西

    RewriteCond %{HTTP_HOST} ^site\.com
    RewriteRule (.*) http://www.site.com/$1 [R=301,L]
    
    #RewriteCond %{SERVER_PORT} !^443$
    #RewriteRule ^products https://www.site.com/products/ [R=301,L]
    
    # Disable SSL on pages other than payments.php
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !^products
    RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]
    
    # Require SSL on payments.php
    RewriteCond %{HTTPS} !on
    RewriteCond %{REQUEST_URI} ^products\/?$
    RewriteRule ^(.*)$ https://www.site.com/$1 [R=301,L]
    
    
    RewriteCond $1 !^(index\.php|images|js|css|static|img|payment|robots\.txt|blank.gif)
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    我的网址是 http://www.sitename.com 后面的正斜杠是可选的 我需要的是,如果url中没有类似文本的产品,则需要使用http://

    如何做到这一点。。。

    我正在使用codeigniter框架,我已经从url中删除了index.php。

    所以如果像 http://sitename.com/products 那么我希望是这样 https://sitename.com/products

        4
  •  -1
  •   William    16 年前
    # Rewrite Rules for example.com
    RewriteEngine On
    RewriteBase /
    
    # Redirect from example.com to www.example.com
    RewriteCond %{HTTP_HOST} ^example\.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
    
    # Disable SSL on pages other than payments.php
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !^payments\.php$
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
    
    # Require SSL on payments.php
    RewriteCond %{HTTPS} !on
    RewriteCond %{REQUEST_URI} ^payments\.php$
    RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
    

    我还没有测试过,但类似的东西应该可以用

    更新

    推荐文章