1

I use codeigniter and I use redirection for all urls to https. now I want to redirect only one page (https://www.example.com/campaign/PPRTasshs-dhshs_fd5656dfhdh/web/surf) to 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

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

Redirect single page http to https

Thanks in advance

Community
  • 1
  • 1

3 Answers3

1

Sounds your ssl and non-ssl version of the page redirects back and forth that's why you get redirect loop. You need to add extra conditions to your redirects. Didn't check but it should work.

For http -> https redirect put this condition too

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 !

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

then redirect to http

Ergec
  • 11,608
  • 7
  • 52
  • 62
1

You have to alter condition at https redirection.and check extra condition at https://www redirection.Just try following code. 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>
Paresh Thummar
  • 933
  • 7
  • 20
0

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>
Saurin Dashadia
  • 1,140
  • 11
  • 25