【问题标题】:Redirect only one page to http htaccess仅将一页重定向到 http htaccess
【发布时间】:2014-10-10 05:58:01
【问题描述】:

我使用 codeigniter,并且我使用重定向所有 url 到 https。现在我只想将一页 (https://www.example.com/campaign/PPRTasshs-dhshs_fd5656dfhdh/web/surf) 重定向到 http。

我在 So 中得到了很多答案。但我无法正确实施。每次我得到错误“这个网页有一个重定向循环”。

我的 htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# the subsequent rule will catch it.

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.

RewriteCond %{SERVER_PORT} 443
RewriteCond $1 (web\/surf|surf)
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]     
RewriteRule ^about-us / [L,R=301]

Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

链接上所以我试过但不适合我。

Codeigniter: Check and force one page to https://

Redirect single page http to https

提前致谢

【问题讨论】:

    标签: php .htaccess codeigniter redirect


    【解决方案1】:

    您必须在 https 重定向处更改条件。并在 https://www 重定向处检查额外条件。只需尝试以下代码。这可能会对您有所帮助。

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    
    RewriteCond %{HTTPS} off
    # First rewrite to HTTPS:
    # the subsequent rule will catch it.
    
    **RewriteCond $1 !(web\/surf|surf)**
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # Now, rewrite any request to the wrong domain to use www.
    
    RewriteCond %{SERVER_PORT} 443
    RewriteCond $1 (web\/surf|surf)
    RewriteRule ^(.*)$ http://www.traffictraject.com/$1 [R=301,L]
    
    RewriteCond %{HTTP_HOST} !^www\.
    **RewriteCond $1 !(web\/surf|surf)**
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    RewriteRule ^about-us / [L,R=301]
    
    Options -Indexes
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
    </IfModule>
    

    【讨论】:

      【解决方案2】:

      听起来你的 ssl 和非 ssl 版本的页面来回重定向,这就是你得到重定向循环的原因。您需要为重定向添加额外的条件。没有检查,但它应该可以工作。

      对于http -> https 重定向也设置此条件

      RewriteCond %{REQUEST_URI} !/campaign/PPRTasshs-dhshs_fd5656dfhdh/web/surf
      

      这应该可以防止重定向循环

      重定向 https -> http 检查 HTTPS 条件 on 并通过删除 ! 检查 url 是否匹配

      RewriteCond %{REQUEST_URI} /campaign/PPRTasshs-dhshs_fd5656dfhdh/web/surf
      

      然后重定向到http

      【讨论】:

        【解决方案3】:

        我希望这会有所帮助。

        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteBase /
        
            RewriteCond %{HTTPS} off
            # First rewrite to HTTPS:
            # the subsequent rule will catch it.
        
            RewriteCond %{SERVER_PORT} 80
            RewriteCond %{REQUEST_URI} !campaign/PPRTasshs-dhshs_fd5656dfhdh/web/surf
            RewriteRule ^(.*)$ https://www.yourdomain.com%{REQUEST_URI} [L,R=301]
        
            Options -Indexes
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ /index.php/$1 [L]
        
            RewriteRule ^about-us / [L,R=301]
        </IfModule>
        
        <IfModule !mod_rewrite.c>
            ErrorDocument 404 /index.php
        </IfModule>
        

        【讨论】:

          猜你喜欢
          • 2012-10-20
          • 1970-01-01
          • 2012-11-07
          • 2013-10-18
          • 1970-01-01
          • 2021-06-13
          • 1970-01-01
          • 2011-01-05
          • 2012-11-02
          相关资源
          最近更新 更多