[SATLUG] mod_rewrite and apache

Channing Channing-C at satx.rr.com
Tue Jan 31 23:03:49 CST 2006


robertc3 <robertc3 at hotmail.com>:

>> On Wednesday 01 February 2006 7:27 am, robertc3 wrote:
>>> I'm trying to redirect users from using http to using https on two
>>> subdirectories on my web server.
>>>
>>> Here's what I have in my httpd.conf so far:
>>>
>>>     RewriteEngine On
>>>     RewriteCond   %{SERVER_PORT}  !^443$
>>>     RewriteRule ^/sc(.*)$ https://%{SERVER_NAME}/sc$1 [L,R]
>>>     RewriteRule ^/internal(.*)$ https://%{SERVER_NAME}/internal$1 [L,R]
>>>
>>> The first one (sc) works fine.  All subdirectories get redirected as
>>> well. The second one (internal) doesn't work and produces the
>>> "Redirection Limit Exceeded" message in Firefox (IE just keeps trying).
>>>
>>
>> The problem is that when you set a RewriteCond, only the next RewriteRule
>> applies.
>>
>> To fix it you could either repeat the RewriteCond before the second rule,
>> or do something tricky like:
>>
>> RewriteCond   %{SERVER_PORT}  ^443$
>> RewriteRule .* - [S=2]
>> RewriteRule ^/sc(.*)$ https://%{SERVER_NAME}/sc$1 [L,R]
>> RewriteRule ^/internal(.*)$ https://%{SERVER_NAME}/internal$1 [L,R]
>>
>> Which is saying if the condition matches, skip the next 2 rules.
>>
>>
>> Julian.
>
> Julian,
>
> I added the
>
> RewriteRule .* - [S=2]
>
> and still no luck.  I also tried adding the RewriteCond rule but I 
> still get the "Redirection Limit Exceeded" message.  Any other 
> suggestions?
>
> Robert
> -- 

Hi Robert,

It's late, but I'll try to help.  Try this on for size.  (Works for me...)

<Directory /var/www/html/internal>
   RewriteEngine On
   RewriteCond %{HTTPS} !=on
   RewriteRule ^/(.*) https://your_domain.com/internal [R,L]
</Directory>

Hope this helps,
Channing

-- 
A: Yes.
> Q: Are you sure?
>> A: Because it reverses the logical flow of conversation.
>>> Q: Why is top posting annoying in email?



More information about the SATLUG mailing list