problem trying to redirect a specific url using SSL
I am trying to redirect all https u开发者_JS百科rls to http (except one account/payment):
RewriteCond %{SERVER_PORT} =80
RewriteCond %{REQUEST_URI} account/payment$
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{SERVER_PORT} =443
RewriteCond %{REQUEST_URI} !account/payment$
RewriteRule (.*) http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule . index.php [L]
Works fine, except when I am going to http://url/account/payment, it's redirect me to http://url/index.php
Thank you
The L flag causes a reinjection of the already rewritten URL into the rewriting process:
Remember, however, that if the
RewriteRule
generates an internal redirect (which frequently occurs when rewriting in a per-directory context), this will reinject the request and will cause processing to be repeated starting from the firstRewriteRule
.
To avoid that either of your first two rules are applied on such a reinjected URL, check the request line instead:
RewriteCond %{SERVER_PORT} =80
RewriteCond %{THE_REQUEST} ^GET\ /account/payment[?\ ]
RewriteRule ^account/payment$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{SERVER_PORT} =443
RewriteCond %{THE_REQUEST} !^GET\ /account/payment[?\ ]
RewriteRule !^account/payment$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Each time a RewriteRule
matches, Apaches does an internal redirect and re-evaluates all the rewrite rules against the new (re-written) path.
So when RewriteRule . index.php
matches, REQUEST_URI is changed to index.php
and all rewrite rules are evaluated again.
RewriteCond %{REQUEST_URI} !account/payment$
evaluates to true against index.php
, and the next rule is evaluated: RewriteRule (.*) http://%{SERVER_NAME}%{REQUEST_URI}
, which redirects (externally) to index.php.
精彩评论