geudrik Posted September 9, 2011 Share Posted September 9, 2011 <VirtualHost *:80> RewriteEngine on # Check to see if /stream.php is called for, and stay on :80 if so RewriteCond ^(.*)$ http://%{SERVER_NAME}/stream.php%{REQUEST_URI}$ RewriteRule $ [L] # Force SSL Connection RewriteCond %{SERVER_PORT} ^80$ RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] </VirtualHost> <VirtualHost _default_:443> # Redirect SSL connection of /stream.php back to :80 RewriteEngine on RewriteCond %{THE_REQUEST} ^[a-zA-Z0-9]{0,200}\ /stream\.php\ HTTP/ [NC] RewriteRule ^.*stream\.php%{REQUEST_URI}$ http://%{SERVER_NAME}:80/ [R=301,L] ... Basically, I am forcing an HTTPS connection (which works great). But what I need to do is bounce back to an http connection if /stream.php is called (and it ONLY resides in the root, but DOES take parameters). Similarly, if stream.php is called on an :80 connection, I need to NOT bounce to :443 connection. The above is about as far as I was able to make it... Apache2 starts up, but my rules don't work :s And the logs really don't say diddly about what's up... Any suggestions? Oh, and one final thing I should add is that doing something like this... RewriteCond %{SERVER_PORT}%{REQUEST_URI} ^80$ !\stream.php$ RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] ... also isn't really an option (though if I have to, that will work... my preference is the prior way). Where am I going wrong? Quote Link to comment https://forums.phpfreaks.com/topic/246754-force-https-except-when-filephp-is-called/ Share on other sites More sharing options...
cags Posted September 9, 2011 Share Posted September 9, 2011 (and it ONLY resides in the root, but DOES take parameters) Stopping stream.php from redirecting on http should be as simple as... RewriteRule ^/stream.php$ - [L] I don't see a reason to check the port, because if they are on port 443 they will end up in the other vhost, but I guess you could keep that in if you really wanted to. Not entirely sure what you mean by DOES take parameters, but I assume you mean only redirect if there's a query string? RewriteCond %{QUERY_STRING} ! ^$ RewriteRule ^/stream.php$ https://%{SERVER_NAME}%{REQUEST_URI} [L,QSA,R=302] Quote Link to comment https://forums.phpfreaks.com/topic/246754-force-https-except-when-filephp-is-called/#findComment-1267249 Share on other sites More sharing options...
geudrik Posted September 16, 2011 Author Share Posted September 16, 2011 I actually have it solved <VirtualHost *:80> RewriteEngine on # RewriteLog /var/log/apache2/rewrite.log # rewriteLogLevel 5 #Try #293 - ONLY redirect if !stream.php RewriteCond %{SCRIPT_FILENAME} !/stream.php RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301] DocumentRoot /var/www </VirtualHost> <VirtualHost _default_:443> RewriteEngine on # RewriteLog /var/log/apache2/rewrite.log # rewriteLogLevel 5 # Force /stream.php to be served on HTTP, { NOT } HTTPS RewriteCond %{SCRIPT_FILENAME} /stream.php RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R] Quote Link to comment https://forums.phpfreaks.com/topic/246754-force-https-except-when-filephp-is-called/#findComment-1270015 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.