Forum Moderators: phranque

Message Too Old, No Replies

Using mod_rewrite with mod_auth protected directories

A solution to a previous problem

         

Bass10

4:37 pm on May 24, 2006 (gmt 0)

10+ Year Member



Hello,

I just thought I'd post the solution to a problem I first addressed with this post:
[webmasterworld.com...]

I've finally had time to get back to the problem and I found a simple solution.

A quick review:
I set up a 301 redirect using mod_rewrite to send all non-www (example.com) requests of a domain to the www (www.example.com) version of the domain. It worked perfectly but I noticed that it didn't work with directories that were protected using mod_auth (requests would fail with a 401 error).

The only solution that I found that worked was to add the redirect in httpd.conf instead an .htaccess file.


Options +FollowSymLinks
# Redirect (301) all requests for example.com to www.example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^/(.*) http://www.example.com/$1 [R=301,L]

Thanks again to jdMorgan and extras for leading me in the right direction.