Go Back   CodingForums.com > :: Client side development > General web building

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-03-2008, 11:15 PM   PM User | #1
Bram2
New Coder

 
Join Date: Nov 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Bram2 is an unknown quantity at this point
Question Can AuthUserFile in .htaccess use a relative path?

I'm using .htaccess to password-protect some pages. The password file is specified with the AuthUserFile value, for example:

AuthUserFile "/home/sites/myusername/httpdocs/.htpasswd"

Now, by using this absolute path, the site cannot easily be moved to another account or even another server or hoster without changing stuff manually, because the above path won't be valid there. I'd have to manually inspect all .htaccess files in the entire site, and change the paths accordingly.

Therefore, I'd prefer to use something like:

AuthUserFile "../.htpasswd"

or

AuthUserFile "%{DOCUMENT_ROOT}/.htpasswd"

or whatever would be relative to my site's local folder. But I can't get this to work.

Is this actually possible, or does .htaccess really ONLY allow absolute paths?

(note: The %{DOCUMENT_ROOT} thing actually gives what I need in RewriteRule, can't that be used with AuthUserFile??)

Last edited by Bram2; 12-03-2008 at 11:30 PM..
Bram2 is offline   Reply With Quote
Old 12-04-2008, 12:53 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
AFAIK, it should be an absolute path. I can't find the info from the apache docs, though an .htaccess file is just an extension of your server's conf file. Thus we may need to follow the same rules here also.
Quote:
Originally Posted by http://support.easystreet.com/hosting/unix/dynamic-config.htm#passwordprotect
The AuthUserFile directive specifies the path to the password file. This must be specified as an absolute path -- if specified as a relative path, the web server will look in its root directory, which is not where your content resides.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 12-04-2008, 02:56 PM   PM User | #3
Bram2
New Coder

 
Join Date: Nov 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Bram2 is an unknown quantity at this point
Well, the apache documentation says:

Quote:
Originally Posted by Apache docs
If it is not absolute (i.e., if it doesn't begin with a slash), it is treated as relative to the ServerRoot.
But I'm not sure what 'ServerRoot' would be.

Besides, if %{DOCUMENT_ROOT} would work like it does with mod_rewrite (in RewriteRule etc), that is an absolute path so that might have done the trick. Except it doesn't...?
Bram2 is offline   Reply With Quote
Old 10-12-2011, 06:27 PM   PM User | #4
ArthurG
New to the CF scene

 
Join Date: Oct 2011
Location: Vermont
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ArthurG is an unknown quantity at this point
Granted the thread is old, but the problem still floats around.

For those who still have this issue of finding their AuthUserFile absolute path to their web space (because your web hosting site is unable to), you can make a simple php file and run it from your site to find the answer.

Use notepad and make a file called myroot.php (or any filename with the .php extension)
copy the following code into the file
--------------------------------------------
<html>
<head>
<title>Getting your AuthUserFile root location</title>
</head>
<?php
echo “<h1>Your website root location is --> “;
echo $_SERVER[‘DOCUMENT_ROOT’];
echo “ <--</h1>”;
?>
<body>
</body>
</html>
---------------------------------------------
Remember to save, and then upload it to your webspace, and run it from a browser on your webspace and copy the path to somewhere safe (and then remember to get rid of the file when you are done using it so a hacker cannot find your AuthUserFile absolute path for your web space).

It'll display the absolute path where your publically accessible webpages are kept, and more often your FTP can upload to one level up (which is a good spot for keeping password files, or making a folder from that level where the public cannot access, but since the AuthUserFile specifies an absolute path on the hard drive, you can choose a folder that you can only get to with an FTP application).

I've had a few ISP that had no clue where the site hosting was being done, much less the absolute path for my webspace, so I setup a little page for people wanting to try using htaccess.

http://home.myfairpoint.net/vze2xgg2...s/htaccess.htm

It provides simple examples which can often be the best to get people started, especially taking the time to explain how and why.

Last edited by ArthurG; 10-12-2011 at 06:29 PM..
ArthurG is offline   Reply With Quote
Reply

Bookmarks

Tags
absolute path, authuserfile, htaccess, relative path

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:59 AM.


Advertisement
Log in to turn off these ads.