Web Hosting Forums

Results 1 to 6 of 6

This is a discussion on Redirect before http authentication in htaccess (not possible) in the Hosting Talk & Chit-chat forum
I've been trying to make a redirect from www to non-www on a directory protected by basic http authentication in an htaccess file. What happens ...

  1. #1
    Loyal Client AdrianB's Avatar
    Join Date
    Apr 2004
    Location
    UmeŚ, Sweden
    Posts
    156

    Redirect before http authentication in htaccess (not possible)

    I've been trying to make a redirect from www to non-www on a directory protected by basic http authentication in an htaccess file.

    What happens when someone enters www.example.com is that they are asked for authentication and when they provide the correct login/password they are redirected to example.com and presented with yet another authentication request.

    From what I've read it's impossible to solve in htaccess since authentication by design always happens before redirect (se this and this for example).

    The only way around this problem is to set this up in httpd.conf instead of using a htaccess file. But I can't do that on a shared server, right?

    Or have I missed something and it really is solvable in htaccess?

  2. #2
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,661
    cURL is your friend...
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

  3. #3
    Loyal Client AdrianB's Avatar
    Join Date
    Apr 2004
    Location
    UmeŚ, Sweden
    Posts
    156
    I really don't see how curl would help me this time...

  4. #4
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,661
    Obviously...
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

  5. #5
    Loyal Client AdrianB's Avatar
    Join Date
    Apr 2004
    Location
    UmeŚ, Sweden
    Posts
    156
    So, would you mind explaining yourself or are you just trying to be annoying? I know the basics of what curl is, but I don't see how it would have anything to do with either mod_rewrite or basic http auth.

    Curl is, AFAIK, used to transfer files. Yes it can be used with http auth, but I don't see how that would affect the limitation of http auth always happening before a redirect.

  6. #6
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    You're right, authentication happens before redirects. There are two solutions that I can think of, though.

    The easy way: ask support if they can set up a redirect in your site's <VirtualHost> entry. Unless this is something that cPanel will automatically overwrite they will probably do it for you.

    The hard way: use a <Files> or <FilesMatch> directive in .htaccess to limit authentication to specific files.
    Code:
    <FilesMatch "(file1.htm)(file2.php)(file3.whatever)">
      #Authentication code goes here
    </FilesMatch>
    You might also try using <FilesMatch "*">, which would match any file. Since the redirect isn't a file it shouldn't get caught, but I haven't tested this, so I don't know what will happen.

    Good luck and let us know what you figure out.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •