简体   繁体   English

仅将一页重定向到http htaccess

[英]Redirect only one page to http htaccess

I use codeigniter and I use redirection for all urls to https. 我使用codeigniter,并将所有URL重定向到https。 now I want to redirect only one page ( https://www.example.com/campaign/PPRTasshs-dhshs_fd5656dfhdh/web/surf ) to http. 现在我只想将一页( https://www.example.com/campaign/PPRTasshs-dhshs_fd5656dfhdh/web/surf )重定向到http。

I got lots of answer in So. 因此,我得到了很多答案。 But I could not implement it properly. 但是我无法正确实现它。 Each time i got error "This webpage has a redirect loop". 每次出现错误“此网页都有重定向循环”。

My htaccess 我的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>

Links on So that I tried but not working for me. 链接,以便我尝试但不为我工作。

Codeigniter: Check and force one page to https:// Codeigniter:检查并强制一页到https://

Redirect single page http to https 将单页http重定向到https

Thanks in advance 提前致谢

You have to alter condition at https redirection.and check extra condition at https://www redirection.Just try following code. 您必须在https重定向中更改条件,并在https://www重定向中检查其他条件。只需尝试以下代码即可。 That may help you. 那可能对您有帮助。

<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>

Sounds your ssl and non-ssl version of the page redirects back and forth that's why you get redirect loop. 听起来页面的ssl和非ssl版本会来回重定向,这就是为什么您会获得重定向循环的原因。 You need to add extra conditions to your redirects. 您需要为重定向添加其他条件。 Didn't check but it should work. 没有检查,但应该可以。

For http -> https redirect put this condition too 对于http > https redirect也要设置此条件

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

This should prevent redirect loop 这应该防止重定向循环

To redirect https -> http check HTTPS condition that is on and check if url matches by removing ! 要重定向https-> http,请检查HTTPS条件是否on并通过删除检查URL是否匹配!

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

then redirect to http 然后重定向到http

I hope this will help. 我希望这将有所帮助。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM