Forum Moderators: phranque
I have a problem. I have I am trying to redirect https url to http except for one page which has to be on https, all others need to be on http using following code
RewriteEngine on
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ [sitename.com...] [R,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^purchase.php$ [userid.powweb.com...] [R,L]
the problem is, when i click on purchase.php from http, it goes into somesort of loop and after sometime you get page cannot be displayed on the browser. First condition is working properly, but for second one i am getting problem. Can anyone help me with this.
Anoop
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI}!^purchase.php$ [NC]
RewriteRule ^(.*)$ [sitename.com...] [R,L]
That will prevent the rewrite of purchase.php if it is called as https. Although it doesn't look like you are doing this, I wonder if because of the shared ssl you are using this is what is actually happening, causing the endless loop.
Thanks, please advice if I should use this as the complete set of rewrite rules
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI}!^purchase.php$ [NC]
RewriteRule ^(.*)$ [sitename.com...] [R,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^purchase.php$ [userid.powweb.com...] [R,L]
Anoop
RewriteEngine on
#
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^purchase\.php$ [NC]
RewriteRule (.*) http://www.sitename.com/$1 [R=301,L]
#
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^purchase\.php$ https://userid.powweb.com/sitename.php [R=301,L]
[edited by: jdMorgan at 5:38 am (utc) on Dec. 23, 2006]
RewriteEngine on
#
RewriteCond %{SERVER_PORT} ^443$
RewriteCond [b]$1[/b] !^purchase\.php$ [NC]
RewriteRule (.*) http://www.sitename.com/$1 [R=301,L]
#
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^purchase\.php$ https://userid.powweb.com/sitename.php [R=301,L]
[edited by: jdMorgan at 3:41 am (utc) on Dec. 24, 2006]
RewriteEngine on
#
RewriteCond %{SERVER_PORT} ^443$
RewriteCond $1!(^securedir/¦\.(css¦gif¦jpe?g¦bmp¦js¦inc)$) [NC,OR]
RewriteCond $1!(^2ndsecuredir/¦\.(css¦gif¦jpe?g¦bmp¦js¦inc)$) [NC,OR]
RewriteCond $1!(^3rdsecuredir/¦\.(css¦gif¦jpe?g¦bmp¦js¦inc)$) [NC]
RewriteRule (.*) http://www.example.com$1 [R=301,L]
The rule worked fine in the non secure directories changing them to http if they were accidentally https. The problems started when I was in one of the three secure dirs and clicked a link or did a reload. I'd get an error message from firefox saying that the server had detected a redirect that it could never complete. Looking at live http headers I could see that it would try and grab the http version instead of the https.
RewriteEngine on
#
RewriteCond %{SERVER_PORT} ^443$
RewriteCond $1 !^(securedir¦2ndsecuredir¦3rdsecuredir)/ [NC,OR]
RewriteCond $1 !\.(css¦gif¦jpe?g¦bmp¦js¦inc)$ [NC]
RewriteRule [b]^/([/b].*) http://www.example.co[b]m/$1[/b] [R=301,L]
After modifying and uploading this code, flush your browser cache (on IE, delete Temporary Internet Files) and re-start your server.
Jim
<VirtualHost 127.0.0.1:8080>
ServerName www.example.com
Port 443
RewriteEngine on
#
RewriteCond %{SERVER_PORT} ^443$
RewriteCond $1!^(securedir¦securedir2¦securedir3)/ [NC,OR]
RewriteCond $1!\.(css¦gif¦jpe?g¦bmp¦js¦inc)$ [NC]
RewriteRule ^/(.*) http://www.example.com/$1 [R=301,L]
</VirtualHost>
Here's the condensed result of Firefox's HTTP Live Headers WITHOUT the rewrite:
[example.com...]
GET /securedir/apc.php HTTP/1.1
HTTP/1.x 200 OK
----------------------------------------------------------
[example.com...]
GET /securedir/apc.php?IMG=2&1168543302 HTTP/1.1
HTTP/1.x 200 OK
----------------------------------------------------------
[example.com...]
GET /securedir/apc.php?IMG=3&1168543302 HTTP/1.1
HTTP/1.x 200 OK
----------------------------------------------------------
[example.com...]
GET /securedir/apc.php?IMG=1&1168543302 HTTP/1.1
HTTP/1.x 200 OK
As you can see, it grabs everything okay.
After the mod_rewrite is installed:
[example.com...]
GET /securedir/apc.php HTTP/1.1
HTTP/1.x 301 Moved Permanently
Location: http://www.example.com/securedir/apc.php
----------------------------------------------------------
http://www.example.com/securedir/apc.php
GET /securedir/apc.php HTTP/1.1
HTTP/1.x 301 Moved Permanently
Location: [example.com...]
And so the loop begins. Not quite sure why it's doing the 301 when securedir is present.
Thanks.
Too bad their rewrite isn't a drop in replacement...guess I have some translating to do.
OR...
Since you'd only be inside that virtualhost if you were coming through an SSL connection, can I just drop:
RewriteCond %{SERVER_PORT} ^443$
from the equation and still keep the rest?