You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Dayton Jones <ed...@gecko.org> on 2006/11/03 16:56:03 UTC

[users@httpd] mod_rewrite help

I'm trying to use mod_rewrite and redirect http requests to https .. 
this is working great, but I need to exlude a specific directory, it has 
to remain http.

I've googled, and read the mod_rewrite documentaion but just can't 
figure this out.  Here is the relevant section from httpd.conf (apache 
2.0.52 running on RHEL 4)

    <VirtualHost xxx.xxx.xxx.xxx:80>
            ServerAdmin noone@nospam.org
            DocumentRoot /vhost/myweb
            ServerName www.mydomain.com
            RewriteEngine on

            RewriteCond   %{REQUEST_URI}  ^/nonssl/$
            RewriteRule ^/(.*)$ http://www.mydomain.com/nonssl/$1 [L,R]

            RewriteCond   %{SERVER_PORT}  !^443$
            RewriteRule ^/(.*)$ https://www.mydomain.com/$1 [L,R]
    </VirtualHost>

I've tried:
    %{REQUEST_URI}  ^/nonssl/.*
    %{REQUEST_URI}  ^/nonssl/*
    %{REQUEST_URI}  ^/nonssl

and none have worked.  What would be the correct RewriteCond and/or 
RewriteRule to redirect all requests except for 
http://www.mydomain.com/nonssl/ to https://www.mydomain.com/ ?

Thanks in advance for any help or insight.     

-- 
+---------------------------------------------------------------+
           Dayton Jones          edge@gecko.org
   "It's better to dig your own grave than to rot in the sun."
+---------------------------------------------------------------+


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite help

Posted by Dayton Jones <ed...@gecko.org>.
Joshua Slive wrote:
> On 11/3/06, Dayton Jones <ed...@gecko.org> wrote:
>> I'm trying to use mod_rewrite and redirect http requests to https ..
>> this is working great, but I need to exlude a specific directory, it has
>> to remain http.
>>
>> I've googled, and read the mod_rewrite documentaion but just can't
>> figure this out.  Here is the relevant section from httpd.conf (apache
>> 2.0.52 running on RHEL 4)
>>
>>     <VirtualHost xxx.xxx.xxx.xxx:80>
>>             ServerAdmin noone@nospam.org
>>             DocumentRoot /vhost/myweb
>>             ServerName www.mydomain.com
>>             RewriteEngine on
>>
>>             RewriteCond   %{REQUEST_URI}  ^/nonssl/$
>>             RewriteRule ^/(.*)$ http://www.mydomain.com/nonssl/$1 [L,R]
>>
>>             RewriteCond   %{SERVER_PORT}  !^443$
>>             RewriteRule ^/(.*)$ https://www.mydomain.com/$1 [L,R]
>>     </VirtualHost>
>>
>> I've tried:
>>     %{REQUEST_URI}  ^/nonssl/.*
>>     %{REQUEST_URI}  ^/nonssl/*
>>     %{REQUEST_URI}  ^/nonssl
>>
>> and none have worked.  What would be the correct RewriteCond and/or
>> RewriteRule to redirect all requests except for
>> http://www.mydomain.com/nonssl/ to https://www.mydomain.com/ ?
>
> RewriteCond %{REQUEST_URI} !^/nonssl
> RewriteRule (.*) https://www.mydomain.com$1 [L,R]
>
> The ServerPort test isn't necessary since you are inside a port-80 vhost.
>
> Joshua.
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server 
> Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org

Ah, thanks.  That worked perfectly.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite help

Posted by Joshua Slive <jo...@slive.ca>.
On 11/3/06, Dayton Jones <ed...@gecko.org> wrote:
> I'm trying to use mod_rewrite and redirect http requests to https ..
> this is working great, but I need to exlude a specific directory, it has
> to remain http.
>
> I've googled, and read the mod_rewrite documentaion but just can't
> figure this out.  Here is the relevant section from httpd.conf (apache
> 2.0.52 running on RHEL 4)
>
>     <VirtualHost xxx.xxx.xxx.xxx:80>
>             ServerAdmin noone@nospam.org
>             DocumentRoot /vhost/myweb
>             ServerName www.mydomain.com
>             RewriteEngine on
>
>             RewriteCond   %{REQUEST_URI}  ^/nonssl/$
>             RewriteRule ^/(.*)$ http://www.mydomain.com/nonssl/$1 [L,R]
>
>             RewriteCond   %{SERVER_PORT}  !^443$
>             RewriteRule ^/(.*)$ https://www.mydomain.com/$1 [L,R]
>     </VirtualHost>
>
> I've tried:
>     %{REQUEST_URI}  ^/nonssl/.*
>     %{REQUEST_URI}  ^/nonssl/*
>     %{REQUEST_URI}  ^/nonssl
>
> and none have worked.  What would be the correct RewriteCond and/or
> RewriteRule to redirect all requests except for
> http://www.mydomain.com/nonssl/ to https://www.mydomain.com/ ?

RewriteCond %{REQUEST_URI} !^/nonssl
RewriteRule (.*) https://www.mydomain.com$1 [L,R]

The ServerPort test isn't necessary since you are inside a port-80 vhost.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org