[nycbug-talk] OT: Apache/mod_rewrite question

David Lawson dave at donnerjack.com
Mon Jan 29 00:47:34 EST 2007


On Jan 29, 2007, at 12:36 AM, Kevin Reiter wrote:

> Kevin Reiter wrote:
>> Kevin Reiter wrote:
>>> Jonathan Stewart wrote:
>>>> Kevin Reiter wrote:
>>>>> All,
>>>>>
>>>>> I've been trying to figure this out for a few hours now, and I  
>>>>> can't
>>>>> quite get it working, and I *know* someone in here knows how to do
>>>>> this...
>>>>>
>>>>> I'm trying to force all traffic to an Apache server (on my  
>>>>> laptop) to
>>>>> use SSL.  The laptop is on a dynamic IP with no static domain,  
>>>>> so I
>>>>> can't force http://machine.domain.tld to https:// 
>>>>> machine.domain.tld,
>>>>> and since the IP changes depending on where I am, I can't use that
>>>>> for a rewrite, either.
>>>>>
>>>>> Do any of you Apache gurus know of a way to do this using an
>>>>> .htaccess file or via a simple edit to httpd.conf?  I've been
>>>>> checking Google for awhile, but everything I've come across  
>>>>> doesn't
>>>>> quite do the trick.
>>>> Not exactly what your asking about but have you considered using a
>>>> dynamic DNS service?  I use No-IP () and have been very happy with
>>>> them.  They even manually setup IPv6 records for me even though  
>>>> they
>>>> are not technically supported.  Although I am paying for a  
>>>> domain name
>>>> and dns they provide free sub-domains as well.  If thats not an  
>>>> option
>>>> I'll see what I can do about a rewrite rule for you.
>>>>
>>>> Jonathan
>>> This is for a traveling laptop that I use both at home and at client
>>> sites, and as a test machine at my new job, so I don't always  
>>> have the
>>> same IP, which is how I typically access the server.
>>>
>>> I should've mentioned that I know about zero when it comes to  
>>> writing
>>> rewrite rules (this would be a first).
>>>
>>> In this case, a dynamic DNS service would do nothing for me (I've  
>>> had a
>>> paid account with FreeDNS[1] for years now.)
>>>
>>> Basically, I'm looking to force the use of SSL on my webserver
>>> (apache+mod_ssl-1.3.37+2.8.28) when the IP and domain are always  
>>> changing.
>>>
>>> I recall seeing something about {SERVER_ADDR} as a variable,  
>>> which would
>>> be exactly what I'm looking for, but I don't have a clue outside  
>>> of that
>>> what to write in the .htaccess file.
>>>
>>
>> Helps when I include the link..
>>
>> [1] http://freedns.afraid.org/
>
> Almost...
>
> Here's what I have for my root .htaccess file:
>
> Options +FollowSymlinks
> RewriteEngine On
> RewriteCond %{SERVER_PORT} !443
> RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [L,R]
>
> ..and this is what I see in the error log after receiving a 500:
> [Mon Jan 29 00:34:18 2007] [alert] [client 10.0.25.20]
> /usr/local/www/data/.htaccess: RewriteEngine not allowed here
>
> Any ideas?

I'm pretty sure you need to flip a switch somewhere in the httpd.conf  
to allow rewrites in .htaccess files.  Frankly, since it looks like  
that file is in your DocumentRoot anyway, I'd just throw that into a  
default VirtualHost in your main httpd.conf (or, better yet, in a  
file in conf.d).

--Dave




More information about the talk mailing list