@@ -794,6 +794,7 @@ function update($event_name,$data) {
794794 if ($ data ['new ' ]['redirect_type ' ] != '' ) {
795795 if (substr ($ data ['new ' ]['redirect_path ' ],-1 ) != '/ ' ) $ data ['new ' ]['redirect_path ' ] .= '/ ' ;
796796 if (substr ($ data ['new ' ]['redirect_path ' ],0 ,8 ) == '[scheme] ' ) $ data ['new ' ]['redirect_path ' ] = '$scheme ' .substr ($ data ['new ' ]['redirect_path ' ],8 );
797+
797798 /* Disabled path extension
798799 if($data['new']['redirect_type'] == 'no' && substr($data['new']['redirect_path'],0,4) != 'http') {
799800 $data['new']['redirect_path'] = $data['new']['document_root'].'/web'.realpath($data['new']['redirect_path']).'/';
@@ -802,22 +803,91 @@ function update($event_name,$data) {
802803
803804 switch ($ data ['new ' ]['subdomain ' ]) {
804805 case 'www ' :
806+ if (substr ($ data ['new ' ]['redirect_path ' ],0 ,1 ) == '/ ' ){ // relative path
807+ $ rewrite_exclude = '(?! ' .substr ($ data ['new ' ]['redirect_path ' ],0 ,-1 ).') ' ;
808+ } else { // URL - check if URL is local
809+ $ tmp_redirect_path = $ data ['new ' ]['redirect_path ' ];
810+ if (substr ($ tmp_redirect_path ,0 ,7 ) == '$scheme ' ) $ tmp_redirect_path = 'http ' .substr ($ tmp_redirect_path ,7 );
811+ $ tmp_redirect_path_parts = parse_url ($ tmp_redirect_path );
812+ if ($ tmp_redirect_path_parts ['host ' ] == $ data ['new ' ]['domain ' ] && ($ tmp_redirect_path_parts ['port ' ] == '80 ' || $ tmp_redirect_path_parts ['port ' ] == '443 ' || !isset ($ tmp_redirect_path_parts ['port ' ]))){
813+ if (substr ($ tmp_redirect_path_parts ['path ' ],-1 ) == '/ ' ) $ tmp_redirect_path_parts ['path ' ] = substr ($ tmp_redirect_path_parts ['path ' ],0 ,-1 );
814+ if (substr ($ tmp_redirect_path_parts ['path ' ],0 ,1 ) != '/ ' ) $ tmp_redirect_path_parts ['path ' ] = '/ ' .$ tmp_redirect_path_parts ['path ' ];
815+ $ rewrite_exclude = '(?! ' .$ tmp_redirect_path_parts ['path ' ].') ' ;
816+ } else {
817+ $ rewrite_exclude = '(.?) ' ;
818+ }
819+ unset($ tmp_redirect_path );
820+ unset($ tmp_redirect_path_parts );
821+ }
805822 $ rewrite_rules [] = array ( 'rewrite_domain ' => '^ ' .$ data ['new ' ]['domain ' ],
806823 'rewrite_type ' => ($ data ['new ' ]['redirect_type ' ] == 'no ' )?'' :$ data ['new ' ]['redirect_type ' ],
807- 'rewrite_target ' => $ data ['new ' ]['redirect_path ' ]);
824+ 'rewrite_target ' => $ data ['new ' ]['redirect_path ' ],
825+ 'rewrite_exclude ' => $ rewrite_exclude );
826+
827+ if (substr ($ data ['new ' ]['redirect_path ' ],0 ,1 ) == '/ ' ){ // relative path
828+ $ rewrite_exclude = '(?! ' .substr ($ data ['new ' ]['redirect_path ' ],0 ,-1 ).') ' ;
829+ } else { // URL - check if URL is local
830+ $ tmp_redirect_path = $ data ['new ' ]['redirect_path ' ];
831+ if (substr ($ tmp_redirect_path ,0 ,7 ) == '$scheme ' ) $ tmp_redirect_path = 'http ' .substr ($ tmp_redirect_path ,7 );
832+ $ tmp_redirect_path_parts = parse_url ($ tmp_redirect_path );
833+ if ($ tmp_redirect_path_parts ['host ' ] == 'www. ' .$ data ['new ' ]['domain ' ] && ($ tmp_redirect_path_parts ['port ' ] == '80 ' || $ tmp_redirect_path_parts ['port ' ] == '443 ' || !isset ($ tmp_redirect_path_parts ['port ' ]))){
834+ if (substr ($ tmp_redirect_path_parts ['path ' ],-1 ) == '/ ' ) $ tmp_redirect_path_parts ['path ' ] = substr ($ tmp_redirect_path_parts ['path ' ],0 ,-1 );
835+ if (substr ($ tmp_redirect_path_parts ['path ' ],0 ,1 ) != '/ ' ) $ tmp_redirect_path_parts ['path ' ] = '/ ' .$ tmp_redirect_path_parts ['path ' ];
836+ $ rewrite_exclude = '(?! ' .$ tmp_redirect_path_parts ['path ' ].') ' ;
837+ } else {
838+ $ rewrite_exclude = '(.?) ' ;
839+ }
840+ unset($ tmp_redirect_path );
841+ unset($ tmp_redirect_path_parts );
842+ }
808843 $ rewrite_rules [] = array ( 'rewrite_domain ' => '^www. ' .$ data ['new ' ]['domain ' ],
809844 'rewrite_type ' => ($ data ['new ' ]['redirect_type ' ] == 'no ' )?'' :$ data ['new ' ]['redirect_type ' ],
810- 'rewrite_target ' => $ data ['new ' ]['redirect_path ' ]);
845+ 'rewrite_target ' => $ data ['new ' ]['redirect_path ' ],
846+ 'rewrite_exclude ' => $ rewrite_exclude );
811847 break ;
812848 case '* ' :
849+ if (substr ($ data ['new ' ]['redirect_path ' ],0 ,1 ) == '/ ' ){ // relative path
850+ $ rewrite_exclude = '(?! ' .substr ($ data ['new ' ]['redirect_path ' ],0 ,-1 ).') ' ;
851+ } else { // URL - check if URL is local
852+ $ tmp_redirect_path = $ data ['new ' ]['redirect_path ' ];
853+ if (substr ($ tmp_redirect_path ,0 ,7 ) == '$scheme ' ) $ tmp_redirect_path = 'http ' .substr ($ tmp_redirect_path ,7 );
854+ $ tmp_redirect_path_parts = parse_url ($ tmp_redirect_path );
855+ if (substr ($ tmp_redirect_path_parts ['host ' ],-strlen ($ data ['new ' ]['domain ' ])) == $ data ['new ' ]['domain ' ] && ($ tmp_redirect_path_parts ['port ' ] == '80 ' || $ tmp_redirect_path_parts ['port ' ] == '443 ' || !isset ($ tmp_redirect_path_parts ['port ' ]))){
856+ if (substr ($ tmp_redirect_path_parts ['path ' ],-1 ) == '/ ' ) $ tmp_redirect_path_parts ['path ' ] = substr ($ tmp_redirect_path_parts ['path ' ],0 ,-1 );
857+ if (substr ($ tmp_redirect_path_parts ['path ' ],0 ,1 ) != '/ ' ) $ tmp_redirect_path_parts ['path ' ] = '/ ' .$ tmp_redirect_path_parts ['path ' ];
858+ $ rewrite_exclude = '(?! ' .$ tmp_redirect_path_parts ['path ' ].') ' ;
859+ } else {
860+ $ rewrite_exclude = '(.?) ' ;
861+ }
862+ unset($ tmp_redirect_path );
863+ unset($ tmp_redirect_path_parts );
864+ }
813865 $ rewrite_rules [] = array ( 'rewrite_domain ' => $ data ['new ' ]['domain ' ],
814866 'rewrite_type ' => ($ data ['new ' ]['redirect_type ' ] == 'no ' )?'' :$ data ['new ' ]['redirect_type ' ],
815- 'rewrite_target ' => $ data ['new ' ]['redirect_path ' ]);
867+ 'rewrite_target ' => $ data ['new ' ]['redirect_path ' ],
868+ 'rewrite_exclude ' => $ rewrite_exclude );
816869 break ;
817870 default :
871+ if (substr ($ data ['new ' ]['redirect_path ' ],0 ,1 ) == '/ ' ){ // relative path
872+ $ rewrite_exclude = '(?! ' .substr ($ data ['new ' ]['redirect_path ' ],0 ,-1 ).') ' ;
873+ } else { // URL - check if URL is local
874+ $ tmp_redirect_path = $ data ['new ' ]['redirect_path ' ];
875+ if (substr ($ tmp_redirect_path ,0 ,7 ) == '$scheme ' ) $ tmp_redirect_path = 'http ' .substr ($ tmp_redirect_path ,7 );
876+ $ tmp_redirect_path_parts = parse_url ($ tmp_redirect_path );
877+ if ($ tmp_redirect_path_parts ['host ' ] == $ data ['new ' ]['domain ' ] && ($ tmp_redirect_path_parts ['port ' ] == '80 ' || $ tmp_redirect_path_parts ['port ' ] == '443 ' || !isset ($ tmp_redirect_path_parts ['port ' ]))){
878+ if (substr ($ tmp_redirect_path_parts ['path ' ],-1 ) == '/ ' ) $ tmp_redirect_path_parts ['path ' ] = substr ($ tmp_redirect_path_parts ['path ' ],0 ,-1 );
879+ if (substr ($ tmp_redirect_path_parts ['path ' ],0 ,1 ) != '/ ' ) $ tmp_redirect_path_parts ['path ' ] = '/ ' .$ tmp_redirect_path_parts ['path ' ];
880+ $ rewrite_exclude = '(?! ' .$ tmp_redirect_path_parts ['path ' ].') ' ;
881+ } else {
882+ $ rewrite_exclude = '(.?) ' ;
883+ }
884+ unset($ tmp_redirect_path );
885+ unset($ tmp_redirect_path_parts );
886+ }
818887 $ rewrite_rules [] = array ( 'rewrite_domain ' => '^ ' .$ data ['new ' ]['domain ' ],
819888 'rewrite_type ' => ($ data ['new ' ]['redirect_type ' ] == 'no ' )?'' :$ data ['new ' ]['redirect_type ' ],
820- 'rewrite_target ' => $ data ['new ' ]['redirect_path ' ]);
889+ 'rewrite_target ' => $ data ['new ' ]['redirect_path ' ],
890+ 'rewrite_exclude ' => $ rewrite_exclude );
821891 }
822892 }
823893
@@ -826,30 +896,30 @@ function update($event_name,$data) {
826896 $ server_alias = array ();
827897 switch ($ data ['new ' ]['subdomain ' ]) {
828898 case 'www ' :
829- $ server_alias [] . = 'www. ' .$ data ['new ' ]['domain ' ].' ' ;
899+ $ server_alias [] = 'www. ' .$ data ['new ' ]['domain ' ].' ' ;
830900 break ;
831901 case '* ' :
832- $ server_alias [] . = '*. ' .$ data ['new ' ]['domain ' ].' ' ;
902+ $ server_alias [] = '*. ' .$ data ['new ' ]['domain ' ].' ' ;
833903 break ;
834904 }
835905 if (is_array ($ aliases )) {
836906 foreach ($ aliases as $ alias ) {
837907 switch ($ alias ['subdomain ' ]) {
838908 case 'www ' :
839- $ server_alias [] . = 'www. ' .$ alias ['domain ' ].' ' .$ alias ['domain ' ].' ' ;
909+ $ server_alias [] = 'www. ' .$ alias ['domain ' ].' ' .$ alias ['domain ' ].' ' ;
840910 break ;
841911 case '* ' :
842- $ server_alias [] . = '*. ' .$ alias ['domain ' ].' ' .$ alias ['domain ' ].' ' ;
912+ $ server_alias [] = '*. ' .$ alias ['domain ' ].' ' .$ alias ['domain ' ].' ' ;
843913 break ;
844914 default :
845- $ server_alias [] . = $ alias ['domain ' ].' ' ;
915+ $ server_alias [] = $ alias ['domain ' ].' ' ;
846916 break ;
847917 }
848918 $ app ->log ('Add server alias: ' .$ alias ['domain ' ],LOGLEVEL_DEBUG );
849919 // Rewriting
850920 if ($ alias ['redirect_type ' ] != '' ) {
851921 if (substr ($ alias ['redirect_path ' ],-1 ) != '/ ' ) $ alias ['redirect_path ' ] .= '/ ' ;
852- if (substr ($ alias ['redirect_path ' ],0 ,8 ) == '[scheme] ' ) $ alias ['redirect_path ' ] = '$scheme ' .substr ($ alias ['redirect_path ' ],8 );
922+ if (substr ($ alias ['redirect_path ' ],0 ,8 ) == '[scheme] ' ) $ alias ['redirect_path ' ] = '$scheme ' .substr ($ alias ['redirect_path ' ],8 );
853923
854924 /* Disabled the path extension
855925 if($data['new']['redirect_type'] == 'no' && substr($data['new']['redirect_path'],0,4) != 'http') {
@@ -859,22 +929,91 @@ function update($event_name,$data) {
859929
860930 switch ($ alias ['subdomain ' ]) {
861931 case 'www ' :
932+ if (substr ($ alias ['redirect_path ' ],0 ,1 ) == '/ ' ){ // relative path
933+ $ rewrite_exclude = '(?! ' .substr ($ alias ['redirect_path ' ],0 ,-1 ).') ' ;
934+ } else { // URL - check if URL is local
935+ $ tmp_redirect_path = $ alias ['redirect_path ' ];
936+ if (substr ($ tmp_redirect_path ,0 ,7 ) == '$scheme ' ) $ tmp_redirect_path = 'http ' .substr ($ tmp_redirect_path ,7 );
937+ $ tmp_redirect_path_parts = parse_url ($ tmp_redirect_path );
938+ if ($ tmp_redirect_path_parts ['host ' ] == $ alias ['domain ' ] && ($ tmp_redirect_path_parts ['port ' ] == '80 ' || $ tmp_redirect_path_parts ['port ' ] == '443 ' || !isset ($ tmp_redirect_path_parts ['port ' ]))){
939+ if (substr ($ tmp_redirect_path_parts ['path ' ],-1 ) == '/ ' ) $ tmp_redirect_path_parts ['path ' ] = substr ($ tmp_redirect_path_parts ['path ' ],0 ,-1 );
940+ if (substr ($ tmp_redirect_path_parts ['path ' ],0 ,1 ) != '/ ' ) $ tmp_redirect_path_parts ['path ' ] = '/ ' .$ tmp_redirect_path_parts ['path ' ];
941+ $ rewrite_exclude = '(?! ' .$ tmp_redirect_path_parts ['path ' ].') ' ;
942+ } else {
943+ $ rewrite_exclude = '(.?) ' ;
944+ }
945+ unset($ tmp_redirect_path );
946+ unset($ tmp_redirect_path_parts );
947+ }
862948 $ rewrite_rules [] = array ( 'rewrite_domain ' => '^ ' .$ alias ['domain ' ],
863949 'rewrite_type ' => ($ alias ['redirect_type ' ] == 'no ' )?'' :$ alias ['redirect_type ' ],
864- 'rewrite_target ' => $ alias ['redirect_path ' ]);
950+ 'rewrite_target ' => $ alias ['redirect_path ' ],
951+ 'rewrite_exclude ' => $ rewrite_exclude );
952+
953+ if (substr ($ alias ['redirect_path ' ],0 ,1 ) == '/ ' ){ // relative path
954+ $ rewrite_exclude = '(?! ' .substr ($ alias ['redirect_path ' ],0 ,-1 ).') ' ;
955+ } else { // URL - check if URL is local
956+ $ tmp_redirect_path = $ alias ['redirect_path ' ];
957+ if (substr ($ tmp_redirect_path ,0 ,7 ) == '$scheme ' ) $ tmp_redirect_path = 'http ' .substr ($ tmp_redirect_path ,7 );
958+ $ tmp_redirect_path_parts = parse_url ($ tmp_redirect_path );
959+ if ($ tmp_redirect_path_parts ['host ' ] == 'www. ' .$ alias ['domain ' ] && ($ tmp_redirect_path_parts ['port ' ] == '80 ' || $ tmp_redirect_path_parts ['port ' ] == '443 ' || !isset ($ tmp_redirect_path_parts ['port ' ]))){
960+ if (substr ($ tmp_redirect_path_parts ['path ' ],-1 ) == '/ ' ) $ tmp_redirect_path_parts ['path ' ] = substr ($ tmp_redirect_path_parts ['path ' ],0 ,-1 );
961+ if (substr ($ tmp_redirect_path_parts ['path ' ],0 ,1 ) != '/ ' ) $ tmp_redirect_path_parts ['path ' ] = '/ ' .$ tmp_redirect_path_parts ['path ' ];
962+ $ rewrite_exclude = '(?! ' .$ tmp_redirect_path_parts ['path ' ].') ' ;
963+ } else {
964+ $ rewrite_exclude = '(.?) ' ;
965+ }
966+ unset($ tmp_redirect_path );
967+ unset($ tmp_redirect_path_parts );
968+ }
865969 $ rewrite_rules [] = array ( 'rewrite_domain ' => '^www. ' .$ alias ['domain ' ],
866970 'rewrite_type ' => ($ alias ['redirect_type ' ] == 'no ' )?'' :$ alias ['redirect_type ' ],
867- 'rewrite_target ' => $ alias ['redirect_path ' ]);
971+ 'rewrite_target ' => $ alias ['redirect_path ' ],
972+ 'rewrite_exclude ' => $ rewrite_exclude );
868973 break ;
869974 case '* ' :
975+ if (substr ($ alias ['redirect_path ' ],0 ,1 ) == '/ ' ){ // relative path
976+ $ rewrite_exclude = '(?! ' .substr ($ alias ['redirect_path ' ],0 ,-1 ).') ' ;
977+ } else { // URL - check if URL is local
978+ $ tmp_redirect_path = $ alias ['redirect_path ' ];
979+ if (substr ($ tmp_redirect_path ,0 ,7 ) == '$scheme ' ) $ tmp_redirect_path = 'http ' .substr ($ tmp_redirect_path ,7 );
980+ $ tmp_redirect_path_parts = parse_url ($ tmp_redirect_path );
981+ if (substr ($ tmp_redirect_path_parts ['host ' ],-strlen ($ alias ['domain ' ])) == $ alias ['domain ' ] && ($ tmp_redirect_path_parts ['port ' ] == '80 ' || $ tmp_redirect_path_parts ['port ' ] == '443 ' || !isset ($ tmp_redirect_path_parts ['port ' ]))){
982+ if (substr ($ tmp_redirect_path_parts ['path ' ],-1 ) == '/ ' ) $ tmp_redirect_path_parts ['path ' ] = substr ($ tmp_redirect_path_parts ['path ' ],0 ,-1 );
983+ if (substr ($ tmp_redirect_path_parts ['path ' ],0 ,1 ) != '/ ' ) $ tmp_redirect_path_parts ['path ' ] = '/ ' .$ tmp_redirect_path_parts ['path ' ];
984+ $ rewrite_exclude = '(?! ' .$ tmp_redirect_path_parts ['path ' ].') ' ;
985+ } else {
986+ $ rewrite_exclude = '(.?) ' ;
987+ }
988+ unset($ tmp_redirect_path );
989+ unset($ tmp_redirect_path_parts );
990+ }
870991 $ rewrite_rules [] = array ( 'rewrite_domain ' => $ alias ['domain ' ],
871992 'rewrite_type ' => ($ alias ['redirect_type ' ] == 'no ' )?'' :$ alias ['redirect_type ' ],
872- 'rewrite_target ' => $ alias ['redirect_path ' ]);
993+ 'rewrite_target ' => $ alias ['redirect_path ' ],
994+ 'rewrite_exclude ' => $ rewrite_exclude );
873995 break ;
874996 default :
997+ if (substr ($ alias ['redirect_path ' ],0 ,1 ) == '/ ' ){ // relative path
998+ $ rewrite_exclude = '(?! ' .substr ($ alias ['redirect_path ' ],0 ,-1 ).') ' ;
999+ } else { // URL - check if URL is local
1000+ $ tmp_redirect_path = $ alias ['redirect_path ' ];
1001+ if (substr ($ tmp_redirect_path ,0 ,7 ) == '$scheme ' ) $ tmp_redirect_path = 'http ' .substr ($ tmp_redirect_path ,7 );
1002+ $ tmp_redirect_path_parts = parse_url ($ tmp_redirect_path );
1003+ if ($ tmp_redirect_path_parts ['host ' ] == $ alias ['domain ' ] && ($ tmp_redirect_path_parts ['port ' ] == '80 ' || $ tmp_redirect_path_parts ['port ' ] == '443 ' || !isset ($ tmp_redirect_path_parts ['port ' ]))){
1004+ if (substr ($ tmp_redirect_path_parts ['path ' ],-1 ) == '/ ' ) $ tmp_redirect_path_parts ['path ' ] = substr ($ tmp_redirect_path_parts ['path ' ],0 ,-1 );
1005+ if (substr ($ tmp_redirect_path_parts ['path ' ],0 ,1 ) != '/ ' ) $ tmp_redirect_path_parts ['path ' ] = '/ ' .$ tmp_redirect_path_parts ['path ' ];
1006+ $ rewrite_exclude = '(?! ' .$ tmp_redirect_path_parts ['path ' ].') ' ;
1007+ } else {
1008+ $ rewrite_exclude = '(.?) ' ;
1009+ }
1010+ unset($ tmp_redirect_path );
1011+ unset($ tmp_redirect_path_parts );
1012+ }
8751013 $ rewrite_rules [] = array ( 'rewrite_domain ' => '^ ' .$ alias ['domain ' ],
8761014 'rewrite_type ' => ($ alias ['redirect_type ' ] == 'no ' )?'' :$ alias ['redirect_type ' ],
877- 'rewrite_target ' => $ alias ['redirect_path ' ]);
1015+ 'rewrite_target ' => $ alias ['redirect_path ' ],
1016+ 'rewrite_exclude ' => $ rewrite_exclude );
8781017 }
8791018 }
8801019 }
0 commit comments