Jump to content

Recommended Posts

<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?

(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]

I actually have it solved :D

<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]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.