htaccess https redirect only on specific Zend Frameworks controller/actions

前端 未结 4 1446
夕颜
夕颜 2021-01-27 05:41

I\'m new to this community, but I\'ve found it really useful time to time.

I\'ve searched for the answer a lot, but I didn\'t find anything like I need. I\'ve tried to s

4条回答
  •  鱼传尺愫
    2021-01-27 06:34

    I have discovered where the origin of the problem is, but I'd still need support to understand how to solve it.

    I have tested on a local linux machine the htaccess and the result was the same... testing separately the two https condition statements (on and off) they work correctly redirecting basing on the given RewriteCond regex. When putting together only the redirect from http to https works. Https to http redirect works only if the regex is not matched, else it redirects to http://www.mydomain.tld/index.php

    So I finally tried to delete the last htaccess statement and it started to work correctly, but, obviously, it does not find the url, as it does not redirect to the index.php anymore.

    It looks like after the correct https redirect the index.php one creates the problem. So I'm asking myself if there is a way to avoid this and make it work correctly.

    As I wrote before, this seems to be a common problem of this htaccess, as its behaviour is the same on the test and on the production server (different linux flavours).

    I put here the working code:

    
    Options +FollowSymLinks
    
    RewriteEngine on
    RewriteBase /
    
    #RewriteCond %{HTTP_HOST} ^mydomain\.tld [NC]
    #RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    
    RewriteCond %{HTTPS} on
    RewriteCond $1 !^((member|shop)/(?!(index|login))(.*))
    RewriteRule ^(.*) http://%{HTTP_HOST}/$1 [L,R=302]
    
    RewriteCond %{HTTPS} off
    RewriteCond $1 ^((member|shop)/(?!(index|login))(.*))
    RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [L,R=302]
    
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteRule !\.(js|ico|gif|jpg|png|css|swf|pdf|txt)$ index.php
    

提交回复
热议问题